Class: N1Loader::ArLazyPreload::AssociatedContextBuilder

Inherits:
ArLazyPreload::AssociatedContextBuilder
  • Object
show all
Defined in:
lib/n1_loader/ar_lazy_preload/associated_context_builder.rb

Overview

Context builder for N1Loader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_context:, association_name:, records:) ⇒ AssociatedContextBuilder

Returns a new instance of AssociatedContextBuilder.



9
10
11
12
# File 'lib/n1_loader/ar_lazy_preload/associated_context_builder.rb', line 9

def initialize(parent_context:, association_name:, records:)
  super(parent_context: parent_context, association_name: association_name)
  @records = records
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



7
8
9
# File 'lib/n1_loader/ar_lazy_preload/associated_context_builder.rb', line 7

def records
  @records
end

Instance Method Details

#performObject



14
15
16
17
18
19
20
# File 'lib/n1_loader/ar_lazy_preload/associated_context_builder.rb', line 14

def perform
  ::ArLazyPreload::Context.register(
    records: records.flatten(1).select { |record| record.respond_to?(:lazy_preload_context=) },
    association_tree: child_association_tree,
    auto_preload: parent_context.auto_preload?
  )
end