Class: Dry::Types::Hash::Schema
- Inherits:
-
Dry::Types::Hash
- Object
- Definition
- Dry::Types::Hash
- Dry::Types::Hash::Schema
- Defined in:
- lib/dry/types/hash/schema.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#member_types ⇒ Object
readonly
Returns the value of attribute member_types.
Attributes inherited from Definition
Attributes included from Options
Instance Method Summary collapse
-
#initialize(primitive, options = {}) ⇒ Schema
constructor
A new instance of Schema.
- #try(hash, &block) ⇒ Object
Methods inherited from Dry::Types::Hash
Methods inherited from Definition
[], #call, #failure, #name, #primitive?, #result, #success
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Options
Constructor Details
#initialize(primitive, options = {}) ⇒ Schema
Returns a new instance of Schema.
7 8 9 10 |
# File 'lib/dry/types/hash/schema.rb', line 7 def initialize(primitive, = {}) @member_types = .fetch(:member_types) super end |
Instance Attribute Details
#member_types ⇒ Object (readonly)
Returns the value of attribute member_types.
5 6 7 |
# File 'lib/dry/types/hash/schema.rb', line 5 def member_types @member_types end |
Instance Method Details
#try(hash, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dry/types/hash/schema.rb', line 12 def try(hash, &block) result = call(hash, :try) if result.values.all?(&:success?) success(result.each_with_object({}) { |(key, res), h| h[key] = res.input }) else failure = failure(hash, result) block ? yield(failure) : failure end end |