Module: Dry::Types::Decorator
Overview
Instance Attribute Summary collapse
Attributes included from Options
#options
Instance Method Summary
collapse
Methods included from Options
#with
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
Delegates missing methods to #type
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/dry/types/decorator.rb', line 82
def method_missing(meth, *args, &block)
if type.respond_to?(meth)
response = type.public_send(meth, *args, &block)
if decorate?(response)
__new__(response)
else
response
end
else
super
end
end
|
Instance Attribute Details
12
13
14
|
# File 'lib/dry/types/decorator.rb', line 12
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
|
#default? ⇒ Boolean
34
35
36
|
# File 'lib/dry/types/decorator.rb', line 34
def default?
type.default?
end
|
#initialize(type) ⇒ Object
15
16
17
18
|
# File 'lib/dry/types/decorator.rb', line 15
def initialize(type, *, **)
super
@type = type
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
51
52
53
|
# File 'lib/dry/types/decorator.rb', line 51
def respond_to_missing?(meth, include_private = false)
super || type.respond_to?(meth)
end
|
#to_proc ⇒ Proc
Wrap the type with a proc
60
61
62
|
# File 'lib/dry/types/decorator.rb', line 60
def to_proc
proc { |value| self.(value) }
end
|
#try(input, &block) ⇒ Result, ...
27
28
29
|
# File 'lib/dry/types/decorator.rb', line 27
def try(input, &block)
type.try(input, &block)
end
|