Class: Dry::Data::Type
- Inherits:
-
Object
show all
- Includes:
- TypeBuilder
- Defined in:
- lib/dry/data/type.rb,
lib/dry/data/type/hash.rb,
lib/dry/data/type/array.rb
Defined Under Namespace
Classes: Array, Hash
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#constrained, #default, #enum, #optional, #safe, #|
Constructor Details
#initialize(constructor, options = {}) ⇒ Type
Returns a new instance of Type.
31
32
33
34
35
|
# File 'lib/dry/data/type.rb', line 31
def initialize(constructor, options = {})
@constructor = constructor
@options = options
@primitive = options.fetch(:primitive)
end
|
Instance Attribute Details
#constructor ⇒ Object
Returns the value of attribute constructor.
11
12
13
|
# File 'lib/dry/data/type.rb', line 11
def constructor
@constructor
end
|
#options ⇒ Object
Returns the value of attribute options.
13
14
15
|
# File 'lib/dry/data/type.rb', line 13
def options
@options
end
|
#primitive ⇒ Object
Returns the value of attribute primitive.
15
16
17
|
# File 'lib/dry/data/type.rb', line 15
def primitive
@primitive
end
|
Class Method Details
.[](primitive) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/dry/data/type.rb', line 17
def self.[](primitive)
if primitive == ::Array
Type::Array
elsif primitive == ::Hash
Type::Hash
else
Type
end
end
|
.constructor(input) ⇒ Object
27
28
29
|
# File 'lib/dry/data/type.rb', line 27
def self.constructor(input)
input
end
|
Instance Method Details
#call(input) ⇒ Object
Also known as:
[]
41
42
43
|
# File 'lib/dry/data/type.rb', line 41
def call(input)
constructor[input]
end
|
#name ⇒ Object
37
38
39
|
# File 'lib/dry/data/type.rb', line 37
def name
primitive.name
end
|
#try(input) ⇒ Object
46
47
48
|
# File 'lib/dry/data/type.rb', line 46
def try(input)
call(input)
end
|
#valid?(input) ⇒ Boolean
50
51
52
|
# File 'lib/dry/data/type.rb', line 50
def valid?(input)
input.is_a?(primitive)
end
|