Class: ArLazyPreload::Preloader
- Inherits:
-
Object
- Object
- ArLazyPreload::Preloader
- Defined in:
- lib/ar_lazy_preload/preloader.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(records, associations) ⇒ Preloader
constructor
A new instance of Preloader.
- #preload ⇒ Object
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
#preload ⇒ Object
20 21 22 |
# File 'lib/ar_lazy_preload/preloader.rb', line 20 def preload ActiveRecord::Associations::Preloader.new.preload(@records, @associations) end |