Module: ArLazyPreload::Base
- Defined in:
- lib/ar_lazy_preload/active_record/base.rb
Overview
ActiveRecord::Base patch with lazy preloading support
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#lazy_preload_context ⇒ Object
Returns the value of attribute lazy_preload_context.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#lazy_preload_context ⇒ Object
Returns the value of attribute lazy_preload_context.
15 16 17 |
# File 'lib/ar_lazy_preload/active_record/base.rb', line 15 def lazy_preload_context @lazy_preload_context end |
Class Method Details
.included(base) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/ar_lazy_preload/active_record/base.rb', line 6 def self.included(base) base.class.delegate :lazy_preload, to: :all base.class.delegate :preload_associations_lazily, to: :all base.after_create { try_setup_auto_preload_context } base.extend(ClassMethods) end |
Instance Method Details
#reload(options = nil) ⇒ Object
19 20 21 |
# File 'lib/ar_lazy_preload/active_record/base.rb', line 19 def reload( = nil) super().tap { try_setup_auto_preload_context } end |
#skip_preload ⇒ Object
23 24 25 26 27 |
# File 'lib/ar_lazy_preload/active_record/base.rb', line 23 def skip_preload lazy_preload_context&.records&.delete(self) self.lazy_preload_context = nil self end |
#try_setup_auto_preload_context ⇒ Object
29 30 31 |
# File 'lib/ar_lazy_preload/active_record/base.rb', line 29 def try_setup_auto_preload_context ArLazyPreload::Context.register(records: [self]) if ArLazyPreload.config.auto_preload? end |