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) ⇒ Object
22
23
24
|
# File 'lib/dry/types/hash.rb', line 22
def permissive(type_map)
schema(type_map, Permissive)
end
|
#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, options.merge(member_types: member_types))
end
|
#strict(type_map) ⇒ Object
26
27
28
|
# File 'lib/dry/types/hash.rb', line 26
def strict(type_map)
schema(type_map, Strict)
end
|
#strict_with_defaults(type_map) ⇒ Object
30
31
32
|
# File 'lib/dry/types/hash.rb', line 30
def strict_with_defaults(type_map)
schema(type_map, StrictWithDefaults)
end
|
#symbolized(type_map) ⇒ Object
34
35
36
|
# File 'lib/dry/types/hash.rb', line 34
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
|