Class: ArLazyPreload::AssociatedContextBuilder
- Inherits:
-
Object
- Object
- ArLazyPreload::AssociatedContextBuilder
- Defined in:
- lib/ar_lazy_preload/associated_context_builder.rb
Overview
This class is responsible for building context for associated records. Given a list of records belonging to the same context and association name it will create and attach a new context to the associated records based on the parent association tree.
Instance Attribute Summary collapse
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#parent_context ⇒ Object
readonly
Returns the value of attribute parent_context.
Instance Method Summary collapse
-
#initialize(parent_context:, association_name:) ⇒ AssociatedContextBuilder
constructor
A new instance of AssociatedContextBuilder.
-
#perform ⇒ Object
Takes all the associated records for the records, attached to the :parent_context and creates a preloading context for them.
Constructor Details
#initialize(parent_context:, association_name:) ⇒ AssociatedContextBuilder
Returns a new instance of AssociatedContextBuilder.
12 13 14 15 |
# File 'lib/ar_lazy_preload/associated_context_builder.rb', line 12 def initialize(parent_context:, association_name:) @parent_context = parent_context @association_name = association_name end |
Instance Attribute Details
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
10 11 12 |
# File 'lib/ar_lazy_preload/associated_context_builder.rb', line 10 def association_name @association_name end |
#parent_context ⇒ Object (readonly)
Returns the value of attribute parent_context.
10 11 12 |
# File 'lib/ar_lazy_preload/associated_context_builder.rb', line 10 def parent_context @parent_context end |
Instance Method Details
#perform ⇒ Object
Takes all the associated records for the records, attached to the :parent_context and creates a preloading context for them
21 22 23 24 25 26 27 28 29 |
# File 'lib/ar_lazy_preload/associated_context_builder.rb', line 21 def perform return if child_association_tree.blank? || associated_records.blank? Context.new( model: reflection.klass, records: associated_records, association_tree: child_association_tree ) end |