Class: ArLazyPreload::Preloader

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, associations) ⇒ Preloader

Returns a new instance of Preloader.



5
6
7
8
# File 'lib/ar_lazy_preload/preloader.rb', line 5

def initialize(records, associations)
  @records = records
  @associations = associations
end

Class Method Details

.patch_for_rails_7!Object



11
12
13
14
15
16
17
# File 'lib/ar_lazy_preload/preloader.rb', line 11

def patch_for_rails_7!
  define_method(:preload) do
    ActiveRecord::Associations::Preloader.new(
      records: @records, associations: @associations
    ).call
  end
end

Instance Method Details

#preloadObject



20
21
22
# File 'lib/ar_lazy_preload/preloader.rb', line 20

def preload
  ActiveRecord::Associations::Preloader.new.preload(@records, @associations)
end