Module: Dry::Types::Decorator
Instance Attribute Summary collapse
Attributes included from Options
#options
Instance Method Summary
collapse
Methods included from Options
#meta, #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
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/dry/types/decorator.rb', line 64
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
41
42
43
|
# File 'lib/dry/types/decorator.rb', line 41
def constrained?
type.constrained?
end
|
18
19
20
|
# File 'lib/dry/types/decorator.rb', line 18
def constructor
type.constructor
end
|
#decorate?(response) ⇒ Boolean
56
57
58
|
# File 'lib/dry/types/decorator.rb', line 56
def decorate?(response)
response.kind_of?(type.class)
end
|
#default? ⇒ Boolean
36
37
38
|
# File 'lib/dry/types/decorator.rb', line 36
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
48
49
50
|
# File 'lib/dry/types/decorator.rb', line 48
def respond_to_missing?(meth, include_private = false)
super || type.respond_to?(meth)
end
|
#try(input, &block) ⇒ Result
25
26
27
|
# File 'lib/dry/types/decorator.rb', line 25
def try(input, &block)
type.try(input, &block)
end
|
#valid?(value) ⇒ Boolean
31
32
33
|
# File 'lib/dry/types/decorator.rb', line 31
def valid?(value)
type.valid?(value)
end
|