class Dry::Types::Hash::Strict
# => Dry::Types::SchemaKeyError: :email is missing in Hash input
hash[email: ‘jane@doe.org’, name: ‘Jane’, age: 21]
hash = Types::Hash.strict(name: Types::String, age: Types::Coercible::Int)
@example
in it.
keys in given hash, and raises a {MissingKeyError} if any key is missing
Strict schema raises a {UnknownKeysError} if there are any unexpected
Strict hash will raise errors when keys are missing or value types are incorrect.
def resolve(hash)
-
(UnknownKeysError)
-
Returns:
-
(Hash{Symbol => Object})
-
Parameters:
-
hash
(Hash
) --
def resolve(hash) unexpected = hash.keys - member_types.keys raise UnknownKeysError.new(*unexpected) unless unexpected.empty? super do |member_type, key, value| type = member_type.default? ? member_type.type : member_type yield(type, key, value) end end