Sha256: 8c69969dbb5fe2ed542bee698370ed573b1bb3dbe562c5ab27412b9ca638c2e4

Contents?: true

Size: 842 Bytes

Versions: 8

Compression:

Stored size: 842 Bytes

Contents

module Refinery
  class BasePresenter

    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
    }

    attr_reader :model

    def initialize(obj)
      @model = obj
    end

    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

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

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
refinerycms-core-3.0.1 app/presenters/refinery/base_presenter.rb
refinerycms-core-3.0.0 app/presenters/refinery/base_presenter.rb
refinerycms-core-2.1.5 app/presenters/refinery/base_presenter.rb
refinerycms-core-2.1.4 app/presenters/refinery/base_presenter.rb
refinerycms-core-2.1.3 app/presenters/refinery/base_presenter.rb
refinerycms-core-2.1.2 app/presenters/refinery/base_presenter.rb
refinerycms-core-2.1.1 app/presenters/refinery/base_presenter.rb
refinerycms-core-2.1.0 app/presenters/refinery/base_presenter.rb