Class: ArLazyPreload::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_lazy_preload/context.rb

Class Method Summary collapse

Class Method Details

.register(records:, association_tree:) ⇒ Object

Initiates lazy preload context for given records



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ar_lazy_preload/context.rb', line 10

def self.register(records:, association_tree:)
  return if records.empty?

  if ArLazyPreload.config.auto_preload?
    Contexts::AutoPreloadContext.new(records: records)
  elsif association_tree.any?
    Contexts::LazyPreloadContext.new(
      records: records,
      association_tree: association_tree
    )
  end
end