Module: N1Loader::ArLazyPreload::LoaderPatch

Included in:
Loader
Defined in:
lib/n1_loader/ar_lazy_preload/loader_patch.rb

Overview

A patch to Loader to setup lazy context lazily.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#context_setupObject

Returns the value of attribute context_setup.



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

def context_setup
  @context_setup
end

Instance Method Details

#loadedObject



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

def loaded
  return @loaded if @already_loaded && @already_context

  super

  synchronize do
    context_setup&.call(@loaded.values.flatten) unless @already_context
  end

  @already_context = true
  @loaded
end