Class: Grape::Validations::CoerceValidator
- Defined in:
- lib/grape/validations/validators/coerce.rb
Defined Under Namespace
Classes: InvalidValue
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
convert_to_short_name, inherited, #initialize, #validate!
Constructor Details
This class inherits a constructor from Grape::Validations::Base
Instance Method Details
#validate_param!(attr_name, params) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/grape/validations/validators/coerce.rb', line 8 def validate_param!(attr_name, params) fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message_key: :coerce unless params.is_a? Hash new_value = coerce_value(@option, params[attr_name]) if valid_type?(new_value) params[attr_name] = new_value else fail Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message_key: :coerce end end |