Class: Nacelle::Cell
- Inherits:
-
Object
- Object
- Nacelle::Cell
- Defined in:
- lib/nacelle/cell.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Class Method Summary collapse
- .action_methods ⇒ Object
- .cache_key ⇒ Object
- .helper(mod) ⇒ Object
- .helper_method(meth) ⇒ Object
- .name ⇒ Object
- .new_with_controller(controller) ⇒ Object
- .updated_at ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
33 34 35 |
# File 'lib/nacelle/cell.rb', line 33 def action @action end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
20 21 22 |
# File 'lib/nacelle/cell.rb', line 20 def end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
20 21 22 |
# File 'lib/nacelle/cell.rb', line 20 def request @request end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
20 21 22 |
# File 'lib/nacelle/cell.rb', line 20 def session @session end |
Class Method Details
.action_methods ⇒ Object
24 25 26 |
# File 'lib/nacelle/cell.rb', line 24 def self.action_methods instance_methods - Class.new(superclass).instance_methods end |
.cache_key ⇒ Object
16 17 18 |
# File 'lib/nacelle/cell.rb', line 16 def self.cache_key to_s # can be overriden to bust caches end |
.helper(mod) ⇒ Object
36 37 38 |
# File 'lib/nacelle/cell.rb', line 36 def self.helper mod helpers << mod end |
.helper_method(meth) ⇒ Object
41 42 43 |
# File 'lib/nacelle/cell.rb', line 41 def self.helper_method meth helper_methods << meth end |
.name ⇒ Object
28 29 30 |
# File 'lib/nacelle/cell.rb', line 28 def self.name to_s.underscore.sub("_cell","") end |
.new_with_controller(controller) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/nacelle/cell.rb', line 3 def self.new_with_controller controller new.tap do |cell| cell.instance_variable_set :@controller, controller cell.instance_variable_set :@request, controller.request cell.instance_variable_set :@session, controller.session cell.instance_variable_set :@cookies, controller.send(:cookies) end end |
.updated_at ⇒ Object
12 13 14 |
# File 'lib/nacelle/cell.rb', line 12 def self.updated_at Time.new(2000) # can be overriden to bust caches end |
Instance Method Details
#render(template: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nacelle/cell.rb', line 45 def render template: nil template ||= "#{self.class.name}/#{action}" assigns = instance_variables.reduce({}) do |hash, key| new_key = key.to_s.split("@").last.to_sym value = instance_variable_get(key) hash.merge(new_key => value) end view_context = @controller.view_context.dup paths = view_context.lookup_context.view_paths + [view_path] view_context.lookup_context.instance_variable_set :@view_paths, paths view_context.assign assigns cell = self helper_methods.each do |meth| view_context.compiled_method_container.define_method meth do cell.send(meth) end end view_context.render template: template end |