Class: ActiveModel::Serializer::Association Private
- Inherits:
-
Struct
- Object
- Struct
- ActiveModel::Serializer::Association
- Defined in:
- lib/active_model/serializer/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.
This class holds all information about serializer’s association.
Instance Attribute Summary collapse
-
#association_options ⇒ Object
Returns the value of attribute association_options.
- #lazy_association ⇒ Object readonly private
-
#reflection ⇒ Object
Returns the value of attribute reflection.
Instance Method Summary collapse
- #belongs_to? ⇒ Boolean private
-
#initialize ⇒ Association
constructor
private
A new instance of Association.
- #key ⇒ Symbol private
- #key? ⇒ True, False private
- #links ⇒ Hash private
-
#meta ⇒ Hash?
private
This gets mutated, so cannot use the cached reflection_options.
- #name ⇒ Symbol private
- #polymorphic? ⇒ Boolean private
- #serializable_hash(adapter_options, adapter_instance) ⇒ Object private
Constructor Details
#initialize ⇒ 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.
12 13 14 15 |
# File 'lib/active_model/serializer/association.rb', line 12 def initialize(*) super @lazy_association = LazyAssociation.new(reflection, ) end |
Instance Attribute Details
#association_options ⇒ Object
Returns the value of attribute association_options
8 9 10 |
# File 'lib/active_model/serializer/association.rb', line 8 def @association_options end |
#lazy_association ⇒ Object (readonly)
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.
9 10 11 |
# File 'lib/active_model/serializer/association.rb', line 9 def lazy_association @lazy_association end |
#reflection ⇒ Object
Returns the value of attribute reflection
8 9 10 |
# File 'lib/active_model/serializer/association.rb', line 8 def reflection @reflection end |
Instance Method Details
#belongs_to? ⇒ 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.
41 42 43 |
# File 'lib/active_model/serializer/association.rb', line 41 def belongs_to? reflection.foreign_key_on == :self end |
#key ⇒ Symbol
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.
21 22 23 |
# File 'lib/active_model/serializer/association.rb', line 21 def key .fetch(:key, name) end |
#key? ⇒ True, False
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.
26 27 28 |
# File 'lib/active_model/serializer/association.rb', line 26 def key? .key?(:key) end |
#links ⇒ Hash
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.
31 32 33 |
# File 'lib/active_model/serializer/association.rb', line 31 def links .fetch(:links) || {} end |
#meta ⇒ Hash?
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.
This gets mutated, so cannot use the cached reflection_options
37 38 39 |
# File 'lib/active_model/serializer/association.rb', line 37 def reflection.[:meta] end |
#name ⇒ Symbol
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.
18 |
# File 'lib/active_model/serializer/association.rb', line 18 delegate :name, to: :reflection |
#polymorphic? ⇒ 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.
45 46 47 |
# File 'lib/active_model/serializer/association.rb', line 45 def polymorphic? true == [:polymorphic] end |
#serializable_hash(adapter_options, adapter_instance) ⇒ 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_model/serializer/association.rb', line 50 def serializable_hash(, adapter_instance) association_serializer = lazy_association.serializer return virtual_value if virtual_value association_object = association_serializer && association_serializer.object return unless association_object serialization = association_serializer.serializable_hash(, {}, adapter_instance) if polymorphic? && serialization polymorphic_type = association_object.class.name.underscore serialization = { type: polymorphic_type, polymorphic_type.to_sym => serialization } end serialization end |