Class: Grape::Validations::Validators::DefaultValidator
- Defined in:
- lib/grape/validations/validators/default_validator.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(attrs, options, required, scope, opts) ⇒ DefaultValidator
constructor
A new instance of DefaultValidator.
- #validate!(params) ⇒ Object
Methods inherited from Base
default_message_key, inherited, new, #validate
Constructor Details
#initialize(attrs, options, required, scope, opts) ⇒ DefaultValidator
Returns a new instance of DefaultValidator.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/grape/validations/validators/default_validator.rb', line 7 def initialize(attrs, , required, scope, opts) super # !important, lazy call at runtime @default_call = if .is_a?(Proc) .arity.zero? ? proc { .call } : elsif .duplicable? proc { .dup } else proc { } end end |
Instance Method Details
#validate!(params) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/grape/validations/validators/default_validator.rb', line 20 def validate!(params) @iterator.each(params) do |resource_params, attr_name| next unless scope.meets_dependency?(resource_params, params) resource_params[attr_name] = @default_call.call(resource_params) if hash_like?(resource_params) && resource_params[attr_name].nil? end end |