Module: RailsPresenter::PresenterHelper

Included in:
PresenterHelper, Base
Defined in:
lib/rails_presenter/presenter_helper.rb

Instance Method Summary collapse

Instance Method Details

#present(object, template = self, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rails_presenter/presenter_helper.rb', line 3

def present(object, template = self, &block)
  if [Array, ActiveRecord::Relation].include? object.class
    return object.map {|e| present(e)}
  end

  begin
    presenter_class = "#{object.class}Presenter".constantize
  rescue NameError
    return object
  end

  presenter = presenter_class.new(object, template)

  block.call(presenter) if block
  presenter
end