Class: Grape::Validations::CoerceValidator

Inherits:
SingleOptionValidator show all
Defined in:
lib/grape/validations/coerce.rb

Defined Under Namespace

Classes: InvalidValue

Instance Attribute Summary

Attributes inherited from Validator

#attrs

Instance Method Summary collapse

Methods inherited from SingleOptionValidator

#initialize

Methods inherited from Validator

inherited, #initialize, #validate!

Constructor Details

This class inherits a constructor from Grape::Validations::SingleOptionValidator

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/grape/validations/coerce.rb', line 10

def validate_param!(attr_name, params)
  new_value = coerce_value(@option, params[attr_name])
  if valid_type?(new_value)
    params[attr_name] = new_value
  else
    raise Grape::Exceptions::ValidationError, :status => 400, :param => attr_name, :message => "invalid parameter: #{attr_name}"
  end
end