class Yaks::Mapper::AssociationMapper

Attributes

association[R]
context[R]
parent_mapper[R]
rel[R]

Public Class Methods

new(parent_mapper, association, context) click to toggle source
# File lib/yaks/mapper/association_mapper.rb, line 6
def initialize(parent_mapper, association, context)
  @parent_mapper = parent_mapper
  @association   = association
  @context       = context.merge(
    mapper_stack: context[:mapper_stack] + [parent_mapper]
  )
  @rel           = association.map_rel(policy) # rubocop:disable Style/ExtraSpacing
end

Public Instance Methods

call(resource) click to toggle source
# File lib/yaks/mapper/association_mapper.rb, line 19
def call(resource)
  if association.render_as_link?(parent_mapper)
    add_link(resource)
  else
    add_subresource(resource)
  end
end
policy() click to toggle source
# File lib/yaks/mapper/association_mapper.rb, line 15
def policy
  context.fetch(:policy)
end

Private Instance Methods

add_subresource(resource) click to toggle source
# File lib/yaks/mapper/association_mapper.rb, line 37
def add_subresource(resource)
  object      = parent_mapper.load_association(association.name)
  subresource = association.map_resource(object, context).add_rel(rel)
  resource.add_subresource(subresource)
end