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: Safe, Schema, Strict, Symbolized
Instance Attribute Summary
Attributes inherited from Definition
Attributes included from Options
Instance Method Summary collapse
Methods inherited from Definition
[], #call, #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::Definition
Instance Method Details
#schema(type_map, klass = Safe) ⇒ 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 = Safe) 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
18 19 20 |
# File 'lib/dry/types/hash.rb', line 18 def strict(type_map) schema(type_map, Strict) end |
#symbolized(type_map) ⇒ Object
22 23 24 |
# File 'lib/dry/types/hash.rb', line 22 def symbolized(type_map) schema(type_map, Symbolized) end |