Class: ActiveModel::Serializer::Reflection
- Inherits:
-
Struct
- Object
- Struct
- ActiveModel::Serializer::Reflection
- Defined in:
- lib/active_model/serializer/reflection.rb
Overview
Holds all the meta-data about an association as it was specified in the ActiveModel::Serializer class.
So you can inspect reflections in your Adapters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#build_association(subject, parent_serializer_options) ⇒ Object
private
Build association.
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
20 21 22 |
# File 'lib/active_model/serializer/reflection.rb', line 20 def name @name end |
#options ⇒ Object
Returns the value of attribute options
20 21 22 |
# File 'lib/active_model/serializer/reflection.rb', line 20 def @options end |
Instance Method Details
#build_association(subject, parent_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.
Build association. This method is used internally to build serializer’s association by its reflection.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_model/serializer/reflection.rb', line 42 def build_association(subject, ) association_value = subject.send(name) = .dup serializer_class = ActiveModel::Serializer.serializer_for(association_value, ) if serializer_class begin serializer = serializer_class.new( association_value, (, ) ) rescue ActiveModel::Serializer::ArraySerializer::NoSerializerError [:virtual_value] = association_value.try(:as_json) || association_value end elsif !association_value.nil? && !association_value.instance_of?(Object) [:virtual_value] = association_value end Association.new(name, serializer, ) end |