Class: Dry::Types::Hash::Strict
- Inherits:
-
Permissive
- Object
- Definition
- Dry::Types::Hash
- Schema
- Permissive
- Dry::Types::Hash::Strict
- Defined in:
- lib/dry/types/hash/schema.rb
Overview
Strict hash will raise errors when keys are missing or value types are incorrect. Strict schema raises a UnknownKeysError if there are any unexpected keys in given hash, and raises a MissingKeyError if any key is missing in it.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Schema
Attributes inherited from Definition
Attributes included from Options
Instance Method Summary collapse
Methods inherited from Permissive
Methods inherited from Schema
#call, #coerce, #initialize, #resolve_missing_value, #try, #try_coerce
Methods included from MaybeTypes
Methods inherited from Dry::Types::Hash
#permissive, #resolve_missing_value, #schema, #strict, #strict_with_defaults, #symbolized, #weak
Methods inherited from Definition
[], #call, #constrained?, #default?, #failure, #initialize, #name, #primitive?, #result, #success, #try
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Options
Constructor Details
This class inherits a constructor from Dry::Types::Hash::Schema
Instance Method Details
#resolve(hash) ⇒ Hash{Symbol => Object} (private)
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/dry/types/hash/schema.rb', line 138 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 |