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.
14 15 16 17 |
# File 'lib/active_model/serializer/association.rb', line 14 def initialize(*) super @lazy_association = LazyAssociation.new(reflection, ) end |
Instance Attribute Details
#association_options ⇒ Object
Returns the value of attribute association_options
10 11 12 |
# File 'lib/active_model/serializer/association.rb', line 10 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.
11 12 13 |
# File 'lib/active_model/serializer/association.rb', line 11 def lazy_association @lazy_association end |
#reflection ⇒ Object
Returns the value of attribute reflection
10 11 12 |
# File 'lib/active_model/serializer/association.rb', line 10 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.
43 44 45 |
# File 'lib/active_model/serializer/association.rb', line 43 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.
23 24 25 |
# File 'lib/active_model/serializer/association.rb', line 23 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.
28 29 30 |
# File 'lib/active_model/serializer/association.rb', line 28 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.
33 34 35 |
# File 'lib/active_model/serializer/association.rb', line 33 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
39 40 41 |
# File 'lib/active_model/serializer/association.rb', line 39 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.
20 |
# File 'lib/active_model/serializer/association.rb', line 20 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.
47 48 49 |
# File 'lib/active_model/serializer/association.rb', line 47 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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_model/serializer/association.rb', line 52 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 |