Class: AmsLazyRelationships::Loaders::Base
- Inherits:
-
Object
- Object
- AmsLazyRelationships::Loaders::Base
- Defined in:
- lib/ams_lazy_relationships/loaders/base.rb
Overview
A base class for all the loaders. A correctly defined loader requires the ‘load_data` and `batch_key` methods.
Direct Known Subclasses
Instance Method Summary collapse
-
#load(record, &block) ⇒ Object
Lazy loads and yields the data when evaluating.
Instance Method Details
#load(record, &block) ⇒ Object
Lazy loads and yields the data when evaluating
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ams_lazy_relationships/loaders/base.rb', line 12 def load(record, &block) BatchLoader.for(record).batch( key: batch_key(record), # Replacing methods can be costly, especially on objects with lots # of methods (like AR methods). Let's disable it. # More info: # https://github.com/exAspArk/batch-loader/tree/v1.4.1#replacing-methods replace_methods: false ) do |records, loader| data = load_data(records, loader) block&.call(data) end end |