Class: TypedParams::Coercer
- Defined in:
- lib/typed_params/coercer.rb
Instance Method Summary collapse
Methods inherited from Mapper
Constructor Details
This class inherits a constructor from TypedParams::Mapper
Instance Method Details
#call(params) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/typed_params/coercer.rb', line 7 def call(params) depth_first_map(params) do |param| schema = param.schema next unless schema.coerce? param.value = schema.type.coerce(param.value) rescue CoercionError type = Types.for(param.value) raise InvalidParameterError.new("failed to coerce #{type} to #{schema.type}", path: param.path, source: schema.source) end end |