Class: Extentions::Collection::Presenter

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/extentions.rb

Instance Method Summary collapse

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

#cachedObject



79
80
81
# File 'lib/extentions.rb', line 79

def cached
  @cached ||= {}
end

#classObject



75
76
77
# File 'lib/extentions.rb', line 75

def class
  __getobj__.class
end