class Dry::Types::Hash::Schema

def try(hash, &block)

Returns:
  • (Object) - if coercion fails and a block is given
  • (Logic::Result) -

Other tags:
    Yieldreturn: -

Other tags:
    Yieldparam: failure -

Parameters:
  • block (#call, nil) --
  • hash (Hash) --
def try(hash, &block)
  success = true
  output  = {}
  begin
    result = try_coerce(hash) do |key, member_result|
      success &&= member_result.success?
      output[key] = member_result.input
      member_result
    end
  rescue ConstraintError, UnknownKeysError, SchemaError => e
    success = false
    result = e
  end
  if success
    success(output)
  else
    failure = failure(output, result)
    block ? yield(failure) : failure
  end
end