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
- #hash_type ⇒ Object private
- #resolve(hash) ⇒ Hash{Symbol => Object} private
Methods inherited from Permissive
Methods inherited from Schema
#call, #coerce, #initialize, #resolve_missing_value, #to_ast, #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, #optional?, #primitive?, #result, #success, #to_ast, #try
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Options
#initialize, #meta, #pristine, #with
Constructor Details
This class inherits a constructor from Dry::Types::Hash::Schema
Instance Method Details
#hash_type ⇒ Object (private)
154 155 156 |
# File 'lib/dry/types/hash/schema.rb', line 154 def hash_type :strict end |
#resolve(hash) ⇒ Hash{Symbol => Object} (private)
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/dry/types/hash/schema.rb', line 166 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 |