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_link(resource)
click to toggle source
# File lib/yaks/mapper/association_mapper.rb, line 29 def add_link(resource) Link.create(rel, association.href) .add_to_resource(resource, parent_mapper, nil) # Yaks::Mapper::Link doesn't do anything with the context, making it # hard to test that we pass it a context. Passing nil for now, until # this is actually needed and can be tested. end
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