Class: Refinery::BasePresenter

Inherits:
Object
  • Object
show all
Defined in:
core/app/presenters/refinery/base_presenter.rb

Direct Known Subclasses

PagePresenter

Constant Summary

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

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ BasePresenter

Returns a new instance of BasePresenter



13
14
15
# File 'core/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 'core/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

#modelObject (readonly)

Returns the value of attribute model



11
12
13
# File 'core/app/presenters/refinery/base_presenter.rb', line 11

def model
  @model
end

Instance Method Details

#respond_to?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'core/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