class Grape::Validations::Types::DryTypeCoercer

dry-rb.org/gems/dry-types/1.2/built-in-types/
but check its type. More information there
If the strict argument is true, it won’t coerce the given value
A base class for classes which must identify a coercer to be used.

def call(val)

Parameters:
  • val (Object) --
def call(val)
  return if val.nil?
  @coercer[val]
rescue Dry::Types::CoercionError => _e
  InvalidValue.new
end

def coercer_instance_for(type, strict = false)

Returns an instance of a coercer for a given type
def coercer_instance_for(type, strict = false)
  klass = type.instance_of?(Class) ? PrimitiveCoercer : collection_coercer_for(type)
  klass.new(type, strict)
end

def collection_coercer_for(type)

#=> Grape::Validations::Types::ArrayCoercer
collection_coercer_for(Array)

Example:
Returns a collection coercer which corresponds to a given type.
def collection_coercer_for(type)
  case type
  when Array
    ArrayCoercer
  when Set
    SetCoercer
  else
    raise ArgumentError, "Unknown type: #{type}"
  end
end

def initialize(type, strict = false)

def initialize(type, strict = false)
  @type = type
  @strict = strict
  @scope = strict ? DryTypes::Strict : DryTypes::Params
end