Class: Dry::Types::Hash
- Inherits:
-
Definition
show all
- Defined in:
- lib/dry/types/hash.rb,
lib/dry/types/hash/schema.rb,
lib/dry/types/extensions/maybe.rb
Direct Known Subclasses
Schema
Defined Under Namespace
Modules: MaybeTypes
Classes: Permissive, Schema, Strict, StrictWithDefaults, Symbolized, Weak
Instance Attribute Summary
Attributes inherited from Definition
#options, #primitive
Attributes included from Options
#options
Instance Method Summary
collapse
Methods inherited from Definition
[], #call, #constrained?, #default?, #failure, #initialize, #name, #primitive?, #result, #success, #try
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Options
#initialize, #meta, #with
Instance Method Details
#permissive(type_map) ⇒ Permissive
31
32
33
|
# File 'lib/dry/types/hash.rb', line 31
def permissive(type_map)
schema(type_map, Permissive)
end
|
#resolve_missing_value(_result, _key, _type) ⇒ Object
58
59
60
|
# File 'lib/dry/types/hash.rb', line 58
def resolve_missing_value(_result, _key, _type)
end
|
#schema(type_map, klass = Schema) ⇒ Schema
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/dry/types/hash.rb', line 11
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, options.merge(member_types: member_types))
end
|
#strict(type_map) ⇒ Strict
37
38
39
|
# File 'lib/dry/types/hash.rb', line 37
def strict(type_map)
schema(type_map, Strict)
end
|
43
44
45
|
# File 'lib/dry/types/hash.rb', line 43
def strict_with_defaults(type_map)
schema(type_map, StrictWithDefaults)
end
|
#symbolized(type_map) ⇒ Symbolized
49
50
51
|
# File 'lib/dry/types/hash.rb', line 49
def symbolized(type_map)
schema(type_map, Symbolized)
end
|
#weak(type_map) ⇒ Weak
25
26
27
|
# File 'lib/dry/types/hash.rb', line 25
def weak(type_map)
schema(type_map, Weak)
end
|