Class: Transmutation::Association Private
- Defined in:
- lib/transmutation/association.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An association: resolves the associated object (via a block or a method on the object) and
serializes it with the looked up serializer, one level deeper. Only rendered within max_depth.
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
-
#initialize(name, namespace: nil, serializer: nil, **options, &block) ⇒ Association
constructor
private
A new instance of Association.
- #render?(serializer) ⇒ Boolean private
- #value(serializer, options) ⇒ Object private
Constructor Details
#initialize(name, namespace: nil, serializer: nil, **options, &block) ⇒ Association
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Association.
9 10 11 12 13 14 |
# File 'lib/transmutation/association.rb', line 9 def initialize(name, namespace: nil, serializer: nil, **, &block) super(name, **, &block) @namespace = namespace @serializer = serializer end |
Instance Method Details
#render?(serializer) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/transmutation/association.rb', line 16 def render?(serializer) super && serializer.depth < serializer.max_depth end |
#value(serializer, options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/transmutation/association.rb', line 20 def value(serializer, ) target = block ? serializer.instance_exec(&block) : serializer.object.send(name) serializer.serialize( target, namespace: @namespace, serializer: @serializer, depth: serializer.depth + 1, max_depth: serializer.max_depth, context: serializer.context ).as_json() end |