class DecentPresenter::Exposure

Attributes

presenter_factory[R]
view_context[R]

Public Class Methods

new(view_context, presenter_factory) click to toggle source
# File lib/decent_presenter/exposure.rb, line 9
def initialize(view_context, presenter_factory)
  @view_context = view_context
  @presenter_factory = presenter_factory
end

Public Instance Methods

present(presentable, options = {}) click to toggle source
# File lib/decent_presenter/exposure.rb, line 14
def present(presentable, options = {})
  if presentable_is_a_collection?(presentable)
    present_collection(presentable, options)
  else
    present_model(presentable, options)
  end
end

Private Instance Methods

present_collection(collection, options = {}) click to toggle source
# File lib/decent_presenter/exposure.rb, line 31
def present_collection(collection, options = {})
  presented_collection = collection.map { |el| present_model(el, options) }
  DecentPresenter::CollectionProxy.new(collection, presented_collection)
end
present_model(presentable, options = {}) click to toggle source
# File lib/decent_presenter/exposure.rb, line 24
def present_model(presentable, options = {})
  presenter = options.fetch(:with) do
    presenter_factory.presenter_for(presentable)
  end
  presenter.new(presentable, view_context)
end
presentable_is_a_collection?(presentable) click to toggle source
# File lib/decent_presenter/exposure.rb, line 36
def presentable_is_a_collection?(presentable)
  [:size, :to_a, :first].all? { |method| presentable.respond_to? method }
end