Class: Dry::Types::Hash
- Inherits:
-
Definition
- Object
- Definition
- Dry::Types::Hash
- Defined in:
- lib/dry/types/hash.rb,
lib/dry/types/hash/schema.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Schema, Strict, Symbolized, Weak
Instance Attribute Summary
Attributes inherited from Definition
Attributes included from Options
Instance Method Summary collapse
- #schema(type_map, klass = Schema) ⇒ Object
- #strict(type_map) ⇒ Object
- #symbolized(type_map) ⇒ Object
- #weak(type_map) ⇒ Object
Methods inherited from Definition
[], #call, #default?, #failure, #initialize, #maybe?, #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::Definition
Instance Method Details
#schema(type_map, klass = Schema) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/dry/types/hash.rb', line 6 def schema(type_map, klass = Schema) member_types = type_map.each_with_object({}) { |(name, type), result| result[name] = case type when String, Class then Types[type] else type end } klass.new(primitive, .merge(member_types: member_types)) end |
#strict(type_map) ⇒ Object
22 23 24 |
# File 'lib/dry/types/hash.rb', line 22 def strict(type_map) schema(type_map, Strict) end |
#symbolized(type_map) ⇒ Object
26 27 28 |
# File 'lib/dry/types/hash.rb', line 26 def symbolized(type_map) schema(type_map, Symbolized) end |
#weak(type_map) ⇒ Object
18 19 20 |
# File 'lib/dry/types/hash.rb', line 18 def weak(type_map) schema(type_map, Weak) end |