class StrongPresenter::PresenterAssociation

@private

Attributes

association[R]
factory[R]
scope[R]

Public Class Methods

new(association, options, &block) click to toggle source
# File lib/strong_presenter/presenter_association.rb, line 5
def initialize(association, options, &block)
  options.assert_valid_keys(:with, :scope)

  @association = association

  @scope = options.delete(:scope)
  @block = block

  @factory = StrongPresenter::Factory.new(options)
end

Public Instance Methods

wrap(parent) click to toggle source
# File lib/strong_presenter/presenter_association.rb, line 16
def wrap(parent)
  associated = parent.send(:object).send(association)
  associated = associated.send(scope) if scope

  factory.wrap(associated) do |presenter|
    parent.instance_exec presenter, &@block if @block
  end
end