Class: Refinery::BasePresenter
- Inherits:
-
Object
- Object
- Refinery::BasePresenter
- Defined in:
- app/presenters/refinery/base_presenter.rb
Constant Summary collapse
- DEFAULT_FIELDS =
{ :title => proc { |p| (p.model.class.name.titleize if p.model.present?) }, :path => proc { |p| p.title }, :browser_title => nil, :meta_description => nil }
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(obj) ⇒ BasePresenter
constructor
A new instance of BasePresenter.
- #method_missing(method, *args) ⇒ Object
- #respond_to?(method, include_all = false) ⇒ Boolean
Constructor Details
#initialize(obj) ⇒ BasePresenter
Returns a new instance of BasePresenter.
13 14 15 |
# File 'app/presenters/refinery/base_presenter.rb', line 13 def initialize(obj) @model = obj end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/presenters/refinery/base_presenter.rb', line 17 def method_missing(method, *args) if @model.respond_to? method, include_all = true @model.send method elsif DEFAULT_FIELDS.has_key? method (value = DEFAULT_FIELDS[method]).is_a?(Proc) ? value.call(self) : value else raise NoMethodError.new("#{self.class.name} doesn't know #{method}. Define or delegate it.", method) end end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
11 12 13 |
# File 'app/presenters/refinery/base_presenter.rb', line 11 def model @model end |
Instance Method Details
#respond_to?(method, include_all = false) ⇒ Boolean
27 28 29 |
# File 'app/presenters/refinery/base_presenter.rb', line 27 def respond_to?(method, include_all = false) super || @model.respond_to?(method, include_all) || DEFAULT_FIELDS.has_key?(method) end |