Class: ActionPresenter::Base
- Inherits:
-
Object
- Object
- ActionPresenter::Base
show all
- Defined in:
- lib/action-presenter/base.rb
Overview
Instance Method Summary
collapse
Constructor Details
#initialize(*args, &block) ⇒ Base
Returns a new instance of Base.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/action-presenter/base.rb', line 12
def initialize(*args, &block)
options = args.
record = args.shift
if record.present?
klass = record.class.respond_to?(:base_class) ? record.class.base_class : record.class
name = klass.name.underscore
self.instance_variable_set("@#{name}", record)
unless self.respond_to?(name)
self.class.send :define_method, name do
instance_variable_get("@#{name}")
end
end
end
options.each do |key, value|
self.send("#{key}=", value)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/action-presenter/base.rb', line 44
def method_missing(method, *args, &block)
if controller.present?
controller.send(:view_context).send(method, *args, &block)
else
super
end
end
|
Instance Method Details
#controller ⇒ Object
32
33
34
|
# File 'lib/action-presenter/base.rb', line 32
def controller
@controller ||= Thread.current[:controller]
end
|
#render ⇒ Object
36
37
38
|
# File 'lib/action-presenter/base.rb', line 36
def render
end
|
#render_json ⇒ Object
40
41
42
|
# File 'lib/action-presenter/base.rb', line 40
def render_json
render.to_json
end
|