Class: Extentions::Collection::Presenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Extentions::Collection::Presenter
- Defined in:
- lib/extentions.rb
Instance Method Summary collapse
- #__class__ ⇒ Object
- #cached ⇒ Object
- #class ⇒ Object
-
#initialize(model, attributes) ⇒ Presenter
constructor
A new instance of Presenter.
-
#method_missing(method, *args, &block) ⇒ Object
TODO lazy init.
Constructor Details
#initialize(model, attributes) ⇒ Presenter
Returns a new instance of Presenter.
56 57 58 59 60 61 |
# File 'lib/extentions.rb', line 56 def initialize(model, attributes) @attributes = attributes super(model) # TODO is this really needed? __getobj__.pointer = self if __getobj__.respond_to? :pointer= end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
TODO lazy init
64 65 66 67 68 69 70 71 72 |
# File 'lib/extentions.rb', line 64 def method_missing(method, *args, &block) return cached[method] if cached.include? method if attributes.include? method @cached[method] = attributes[method].call.to_s.html_safe else super end end |
Instance Method Details
#__class__ ⇒ Object
74 |
# File 'lib/extentions.rb', line 74 alias_method :__class__, :class |
#cached ⇒ Object
79 80 81 |
# File 'lib/extentions.rb', line 79 def cached @cached ||= {} end |
#class ⇒ Object
75 76 77 |
# File 'lib/extentions.rb', line 75 def class __getobj__.class end |