Class: Yaks::Mapper::AssociationMapper
- Inherits:
-
Object
- Object
- Yaks::Mapper::AssociationMapper
- Defined in:
- lib/yaks/mapper/association_mapper.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#parent_mapper ⇒ Object
readonly
Returns the value of attribute parent_mapper.
-
#rel ⇒ Object
readonly
Returns the value of attribute rel.
Instance Method Summary collapse
- #call(resource) ⇒ Object
-
#initialize(parent_mapper, association, context) ⇒ AssociationMapper
constructor
A new instance of AssociationMapper.
- #policy ⇒ Object
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
#association ⇒ Object (readonly)
Returns the value of attribute association.
4 5 6 |
# File 'lib/yaks/mapper/association_mapper.rb', line 4 def association @association end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/yaks/mapper/association_mapper.rb', line 4 def context @context end |
#parent_mapper ⇒ Object (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 |
#rel ⇒ Object (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 |
#policy ⇒ Object
15 16 17 |
# File 'lib/yaks/mapper/association_mapper.rb', line 15 def policy context.fetch(:policy) end |