Skip to content

Instantly share code, notes, and snippets.

@rx
Created September 8, 2021 12:12
Show Gist options
  • Save rx/dc9cc7a72e81ec5ae115482331514072 to your computer and use it in GitHub Desktop.
Save rx/dc9cc7a72e81ec5ae115482331514072 to your computer and use it in GitHub Desktop.
Service Validation Example
module Services
class DoesSomething < BaseService
def initialize(model_ids:)
@model_ids = model_ids
validate_params
end
def call
# Your service logic goes here
success
end
alias perform call
private
def validate_params
if @model_ids.empty
raise ::Errors::ParameterValidation, 'No model ids provides. You must pass at least one model id.'
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment