class Dry::Types::Hash::Schema
def try(hash)
-
(Object)
- if coercion fails and a block is given -
(Logic::Result)
-
Other tags:
- Yieldreturn: -
Other tags:
- Yieldparam: failure -
Parameters:
-
hash
(Hash
) --
def try(hash) if hash.is_a?(::Hash) 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, MissingKeyError => e success = false result = e end else success = false output = hash result = "#{hash} must be a hash" end if success success(output) else failure = failure(output, result) block_given? ? yield(failure) : failure end end