class Draper::DecoratedAssociation

@private

Attributes

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

Public Class Methods

new(owner, association, options) click to toggle source
# File lib/draper/decorated_association.rb, line 5
def initialize(owner, association, options)
  options.assert_valid_keys(:with, :scope, :context)

  @owner = owner
  @association = association

  @scope = options[:scope]

  decorator_class = options[:with]
  context = options.fetch(:context, ->(context){ context })
  @factory = Draper::Factory.new(with: decorator_class, context: context)
end

Public Instance Methods

call() click to toggle source
# File lib/draper/decorated_association.rb, line 18
def call
  decorate unless defined?(@decorated)
  @decorated
end

Private Instance Methods

decorate() click to toggle source
# File lib/draper/decorated_association.rb, line 27
def decorate
  associated = owner.object.send(association)
  associated = associated.send(scope) if scope

  @decorated = factory.decorate(associated, context_args: owner.context)
end