Class: Yaks::Mapper::AssociationMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/yaks/mapper/association_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_mapper, association, context) ⇒ AssociationMapper

Returns a new instance of AssociationMapper.



6
7
8
9
10
11
12
13
# 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

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



4
5
6
# File 'lib/yaks/mapper/association_mapper.rb', line 4

def association
  @association
end

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/yaks/mapper/association_mapper.rb', line 4

def context
  @context
end

#parent_mapperObject (readonly)

Returns the value of attribute parent_mapper.



4
5
6
# File 'lib/yaks/mapper/association_mapper.rb', line 4

def parent_mapper
  @parent_mapper
end

#relObject (readonly)

Returns the value of attribute rel.



4
5
6
# File 'lib/yaks/mapper/association_mapper.rb', line 4

def rel
  @rel
end

Instance Method Details

#call(resource) ⇒ Object



19
20
21
22
23
24
25
# 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

#policyObject



15
16
17
# File 'lib/yaks/mapper/association_mapper.rb', line 15

def policy
  context.fetch(:policy)
end