Class: Grape::Validations::ValuesValidator
- Defined in:
- lib/grape/validations/values.rb
Instance Attribute Summary
Attributes inherited from Validator
Instance Method Summary collapse
-
#initialize(attrs, options, required, scope) ⇒ ValuesValidator
constructor
A new instance of ValuesValidator.
- #validate_param!(attr_name, params) ⇒ Object
Methods inherited from Validator
convert_to_short_name, inherited, #validate!
Constructor Details
#initialize(attrs, options, required, scope) ⇒ ValuesValidator
Returns a new instance of ValuesValidator.
4 5 6 7 8 |
# File 'lib/grape/validations/values.rb', line 4 def initialize(attrs, , required, scope) @values = @required = required super end |
Instance Method Details
#validate_param!(attr_name, params) ⇒ Object
10 11 12 13 14 |
# File 'lib/grape/validations/values.rb', line 10 def validate_param!(attr_name, params) if (params[attr_name] || required_for_root_scope?) && !(@values.is_a?(Proc) ? @values.call : @values).include?(params[attr_name]) raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message_key: :values end end |