Class: Dry::Types::Hash::Weak
- Inherits:
-
Schema
- Object
- Definition
- Dry::Types::Hash
- Schema
- Dry::Types::Hash::Weak
- Defined in:
- lib/dry/types/hash/schema.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Schema
Attributes inherited from Definition
Attributes included from Options
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Schema
Methods included from MaybeTypes
Methods inherited from Dry::Types::Hash
#permissive, #schema, #strict, #strict_with_defaults, #symbolized, #weak
Methods inherited from Definition
[], #call, #constrained?, #default?, #failure, #initialize, #name, #primitive?, #result, #success
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
Class Method Details
.new(primitive, options) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/dry/types/hash/schema.rb', line 116 def self.new(primitive, ) member_types = . fetch(:member_types). each_with_object({}) { |(k, t), res| res[k] = t.safe } super(primitive, .merge(member_types: member_types)) end |
Instance Method Details
#try(hash, &block) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/dry/types/hash/schema.rb', line 124 def try(hash, &block) if hash.is_a?(::Hash) super else result = failure(hash, "#{hash} must be a hash") block ? yield(result) : result end end |