Class: BlockHelpers::Base
- Inherits:
-
Object
- Object
- BlockHelpers::Base
show all
- Defined in:
- lib/block_helpers.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/block_helpers.rb', line 52
def method_missing(method, *args, &block)
if helper.respond_to?(method)
self.class_eval "def #{method}(*args, &block); helper.send('#{method}', *args, &block); end"
self.send(method, *args, &block)
else
super
end
end
|
Class Method Details
.inherited(klass) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/block_helpers.rb', line 7
def self.inherited(klass)
method_name = klass.name.split('::').last.underscore
klass.parent.class_eval %(
def #{method_name}(*args, &block)
renderer = #{klass.name}.new(*args)
top_level_helper = if self.is_a?(BlockHelpers::Base)
self.helper
else
self
end
renderer.send(:helper=, top_level_helper)
body = block ? capture(renderer, &block) : nil
processed_body = renderer.display(body)
if processed_body
if top_level_helper.method(:concat).arity == 2
concat processed_body, binding
else
concat processed_body
end
end
renderer
end
)
end
|
Instance Method Details
#display(body) ⇒ Object
40
41
42
|
# File 'lib/block_helpers.rb', line 40
def display(body)
body
end
|
#respond_to?(method) ⇒ Boolean
44
45
46
|
# File 'lib/block_helpers.rb', line 44
def respond_to?(method)
super or helper.respond_to?(method)
end
|