Module: Dry::Types::Decorator
Instance Attribute Summary collapse
Attributes included from Options
#options
Instance Method Summary
collapse
Methods included from Options
#meta, #pristine, #with
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
Delegates missing methods to #type
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/dry/types/decorator.rb', line 65
def method_missing(meth, *args, &block)
if type.respond_to?(meth)
response = type.__send__(meth, *args, &block)
if decorate?(response)
self.class.new(response, options)
else
response
end
else
super
end
end
|
Instance Attribute Details
9
10
11
|
# File 'lib/dry/types/decorator.rb', line 9
def type
@type
end
|
Instance Method Details
#constrained? ⇒ Boolean
42
43
44
|
# File 'lib/dry/types/decorator.rb', line 42
def constrained?
type.constrained?
end
|
18
19
20
|
# File 'lib/dry/types/decorator.rb', line 18
def constructor
type.constructor
end
|
#decorate?(response) ⇒ Boolean
57
58
59
|
# File 'lib/dry/types/decorator.rb', line 57
def decorate?(response)
response.kind_of?(type.class)
end
|
#default? ⇒ Boolean
37
38
39
|
# File 'lib/dry/types/decorator.rb', line 37
def default?
type.default?
end
|
#initialize(type) ⇒ Object
12
13
14
15
|
# File 'lib/dry/types/decorator.rb', line 12
def initialize(type, *)
super
@type = type
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
49
50
51
|
# File 'lib/dry/types/decorator.rb', line 49
def respond_to_missing?(meth, include_private = false)
super || type.respond_to?(meth)
end
|
#try(input, &block) ⇒ Result, ...
26
27
28
|
# File 'lib/dry/types/decorator.rb', line 26
def try(input, &block)
type.try(input, &block)
end
|
#valid?(value) ⇒ Boolean
32
33
34
|
# File 'lib/dry/types/decorator.rb', line 32
def valid?(value)
type.valid?(value)
end
|