module SealinkParamValidation::Concern
Public Class Methods
schema_for(action, schema = nil)
click to toggle source
# File lib/sealink_param_validation/concern.rb, line 15 def self.schema_for(action, schema = nil) schemas[action.to_sym] = schema if schema before_action :ensure_schema end
Private Instance Methods
action()
click to toggle source
# File lib/sealink_param_validation/concern.rb, line 38 def action params['action'].to_sym end
ensure_schema()
click to toggle source
# File lib/sealink_param_validation/concern.rb, line 30 def ensure_schema schema = schema_for_action return unless schema.present? @validation_result = schema.call(params.to_unsafe_h) return if @validation_result.success? render json: {error: SealinkParamValidation::Helper.generate_error_message(@validation_result)}, status: 422 end
ensure_schema!()
click to toggle source
# File lib/sealink_param_validation/concern.rb, line 23 def ensure_schema! @validation_result = schema_for_action.call(params.to_unsafe_h) return if @validation_result.success? error = SealinkParamValidation::Helper.generate_humanized_error_message(@validation_result) fail SealinkParamValidation::InvalidInputError, error end
schema_for_action()
click to toggle source
# File lib/sealink_param_validation/concern.rb, line 42 def schema_for_action self.class.schemas[action] end