一键导入
service-objects
Service object patterns, Result objects, and validation conventions for this Rails codebase
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Service object patterns, Result objects, and validation conventions for this Rails codebase
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Create, execute, update, and complete implementation plans and trackers following Linkvan API conventions
Standardized Ruby gem update workflow with version checking, breaking change analysis, security advisory detection, and testing
Controller patterns, service delegation, strong parameters, and HTTP conventions for this Rails codebase
RuboCop metrics, Brakeman security, code style conventions, and quality checks for this Rails codebase
Database migration patterns, reversible migrations, indexes, and conventions for this Rails codebase
ActiveRecord model patterns, validations, scopes, and conventions for this Rails codebase
| name | service-objects |
| description | Service object patterns, Result objects, and validation conventions for this Rails codebase |
All services inherit from ApplicationService and follow this structure:
class MyService < ApplicationService
def initialize(arg1, arg2)
super()
@arg1 = arg1
@arg2 = arg2
end
def call
return Result.new(errors: ["validation error"]) unless valid?
Result.new(data: result_data)
end
private
def validate
add_error("Invalid input") if invalid_condition?
end
end
# Call service directly
result = MyService.call(arg1, arg2)
# Check for errors
if result.errors.any?
# Handle errors
else
# Use result.data
end
FacilitySerializer)facility_serializer.rbapp/services/ directoryResult objectsResult.new(errors: [...]) for validation failuresResult.new(data: ...) for successful operationsresult.errors.any? to determine success/failurevalidate methods for validation logicadd_error(message) to collect validation errorsraise for programmer errorsResult.new(errors: [...]) for service object validation failuresbegin/rescue blocks when necessaryspec/services/*_service_spec.rb suffix (e.g., facility_serializer_spec.rb)