Class: ActiveModel::Serializer::LazyAssociation Private
- Inherits:
-
Struct
- Object
- Struct
- ActiveModel::Serializer::LazyAssociation
- Defined in:
- lib/active_model/serializer/lazy_association.rb
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.
Constant Summary collapse
- REFLECTION_OPTIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i(key links polymorphic meta serializer virtual_value namespace).freeze
Instance Attribute Summary collapse
-
#association_options ⇒ Object
Returns the value of attribute association_options.
-
#reflection ⇒ Object
Returns the value of attribute reflection.
Instance Method Summary collapse
- #include_data? ⇒ Boolean private
- #object ⇒ Object (also: #eval_reflection_block) private
- #reflection_options ⇒ Object private
- #serializer ⇒ ActiveModel::Serializer? private
- #serializer_class ⇒ Object private
- #virtual_value ⇒ Object private
Instance Attribute Details
#association_options ⇒ Object
Returns the value of attribute association_options
6 7 8 |
# File 'lib/active_model/serializer/lazy_association.rb', line 6 def @association_options end |
#reflection ⇒ Object
Returns the value of attribute reflection
6 7 8 |
# File 'lib/active_model/serializer/lazy_association.rb', line 6 def reflection @reflection end |
Instance Method Details
#include_data? ⇒ 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.
24 25 26 27 28 29 |
# File 'lib/active_model/serializer/lazy_association.rb', line 24 def include_data? eval_reflection_block if reflection.block reflection.include_data?( .fetch(:include_slice) ) end |
#object ⇒ Object Also known as: eval_reflection_block
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.
15 16 17 18 19 20 21 |
# File 'lib/active_model/serializer/lazy_association.rb', line 15 def object return @object if defined?(@object) @object = reflection.value( .fetch(:parent_serializer), .fetch(:include_slice) ) end |
#reflection_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.
11 12 13 |
# File 'lib/active_model/serializer/lazy_association.rb', line 11 def @reflection_options ||= reflection..select { |k, _| REFLECTION_OPTIONS.include?(k) } end |
#serializer ⇒ ActiveModel::Serializer?
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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/active_model/serializer/lazy_association.rb', line 32 def serializer return @serializer if defined?(@serializer) if serializer_class serialize_object!(object) elsif !object.nil? && !object.instance_of?(Object) cached_result[:virtual_value] = object end @serializer = cached_result[:serializer] end |
#serializer_class ⇒ 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.
46 47 48 49 50 51 |
# File 'lib/active_model/serializer/lazy_association.rb', line 46 def serializer_class return @serializer_class if defined?(@serializer_class) = { namespace: namespace } [:serializer] = [:serializer] if .key?(:serializer) @serializer_class = .fetch(:parent_serializer).class.serializer_for(object, ) end |
#virtual_value ⇒ 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.
42 43 44 |
# File 'lib/active_model/serializer/lazy_association.rb', line 42 def virtual_value cached_result[:virtual_value] || [:virtual_value] end |