Class: Dry::View::ValuePart
- Inherits:
-
Part
- Object
- Part
- Dry::View::ValuePart
show all
- Defined in:
- lib/dry/view/value_part.rb
Instance Attribute Summary collapse
Attributes inherited from Part
#renderer
Instance Method Summary
collapse
Methods inherited from Part
#render, #template?
Constructor Details
#initialize(renderer, data) ⇒ ValuePart
Returns a new instance of ValuePart.
11
12
13
14
15
|
# File 'lib/dry/view/value_part.rb', line 11
def initialize(renderer, data)
super(renderer)
@_data = data
@_value = data.values[0]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/dry/view/value_part.rb', line 35
def method_missing(meth, *args, &block)
template_path = template?(meth)
if template_path
render(template_path, &block)
elsif _data.key?(meth)
_data[meth]
elsif _value.respond_to?(meth)
_value.public_send(meth, *args, &block)
else
super
end
end
|
Instance Attribute Details
#_data ⇒ Object
Returns the value of attribute _data.
9
10
11
|
# File 'lib/dry/view/value_part.rb', line 9
def _data
@_data
end
|
#_value ⇒ Object
Returns the value of attribute _value.
9
10
11
|
# File 'lib/dry/view/value_part.rb', line 9
def _value
@_value
end
|
Instance Method Details
#[](key) ⇒ Object
21
22
23
|
# File 'lib/dry/view/value_part.rb', line 21
def [](key)
_value[key]
end
|
#each(&block) ⇒ Object
25
26
27
|
# File 'lib/dry/view/value_part.rb', line 25
def each(&block)
_value.each(&block)
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
29
30
31
|
# File 'lib/dry/view/value_part.rb', line 29
def respond_to_missing?(meth, include_private = false)
_data.key?(meth) || super
end
|
#to_s ⇒ Object
17
18
19
|
# File 'lib/dry/view/value_part.rb', line 17
def to_s
_value.to_s
end
|