Class: Grape::Validations::Validators::ValuesValidator
- Defined in:
- lib/grape/validations/validators/values_validator.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(attrs, options, required, scope, **opts) ⇒ ValuesValidator
constructor
A new instance of ValuesValidator.
- #validate_param!(attr_name, params) ⇒ Object
Methods inherited from Base
#fail_fast?, inherited, #message, #options_key?, #validate, #validate!
Constructor Details
#initialize(attrs, options, required, scope, **opts) ⇒ ValuesValidator
Returns a new instance of ValuesValidator.
7 8 9 10 |
# File 'lib/grape/validations/validators/values_validator.rb', line 7 def initialize(attrs, , required, scope, **opts) @values = .is_a?(Hash) ? [:value] : super end |
Instance Method Details
#validate_param!(attr_name, params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/grape/validations/validators/values_validator.rb', line 12 def validate_param!(attr_name, params) return unless params.is_a?(Hash) val = params[attr_name] return if val.nil? && !required_for_root_scope? # don't forget that +false.blank?+ is true return if val != false && val.blank? && @allow_blank return if check_values?(val, attr_name) raise Grape::Exceptions::Validation.new( params: [@scope.full_name(attr_name)], message: (:values) ) end |