Module: N1Loader::Loadable
- Includes:
- ArLazyPreload::Loadable
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/n1_loader/core/loadable.rb
Overview
The module to be included to the class to define associated loaders.
class Example
include N1Loader::Loadable
# with inline loader
n1_optimized :something do
def perform(elements)
elements.each { |element| fulfill(element, element.calculate_something) }
end
end
# with custom loader
n1_optimized :something, MyLoader
end
# custom loader
class MyLoader < N1Loader::Loader
def perform(elements)
elements.each { |element| fulfill(element, element.calculate_something) }
end
end
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #n1_clear_cache ⇒ Object
- #n1_loader(name) ⇒ Object
- #n1_loader_reload(name) ⇒ Object
- #n1_loaders ⇒ Object
Class Method Details
.included(base) ⇒ Object
45 46 47 |
# File 'lib/n1_loader/core/loadable.rb', line 45 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#n1_clear_cache ⇒ Object
39 40 41 42 43 |
# File 'lib/n1_loader/core/loadable.rb', line 39 def n1_clear_cache self.class.n1_loaders.each_key do |name| n1_loaders[name] = nil end end |
#n1_loader(name) ⇒ Object
31 32 33 |
# File 'lib/n1_loader/core/loadable.rb', line 31 def n1_loader(name) n1_loaders[name] end |
#n1_loader_reload(name) ⇒ Object
35 36 37 |
# File 'lib/n1_loader/core/loadable.rb', line 35 def n1_loader_reload(name) n1_loaders[name] = LoaderCollection.new(self.class.n1_loaders[name], [self]) end |
#n1_loaders ⇒ Object
27 28 29 |
# File 'lib/n1_loader/core/loadable.rb', line 27 def n1_loaders @n1_loaders ||= {} end |