Class: Refinery::BasePresenter

Inherits:
Object
  • Object
show all
Defined in:
core/lib/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,
  :meta_keywords      => nil
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BasePresenter) initialize(obj)

A new instance of BasePresenter



14
15
16
# File 'core/lib/refinery/base_presenter.rb', line 14

def initialize(obj)
  @model = obj
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args)



18
19
20
21
22
23
24
25
26
# File 'core/lib/refinery/base_presenter.rb', line 18

def method_missing(method, *args)
  if @model.respond_to? method
    @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

- (Object) model (readonly)

Returns the value of attribute model



12
13
14
# File 'core/lib/refinery/base_presenter.rb', line 12

def model
  @model
end

Instance Method Details

- (Boolean) respond_to?(method)

Returns:

  • (Boolean)


28
29
30
# File 'core/lib/refinery/base_presenter.rb', line 28

def respond_to?(method)
  super || @model.respond_to?(method) || DEFAULT_FIELDS.has_key?(method)
end