Module: N1Loader::Loadable

Includes:
Name
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_loader :something do
    def perform(elements)
      elements.each { |element| fulfill(element, element.calculate_something) }
    end
  end

  # with custom loader
  n1_loader :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

Methods included from Name

#n1_loader_name

Class Method Details

.included(base) ⇒ Object



47
48
49
# File 'lib/n1_loader/core/loadable.rb', line 47

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#n1_clear_cacheObject



41
42
43
44
45
# File 'lib/n1_loader/core/loadable.rb', line 41

def n1_clear_cache
  self.class.n1_loaders.each do |name|
    n1_loader_set(name, nil)
  end
end

#n1_loader(name) ⇒ Object



29
30
31
32
33
# File 'lib/n1_loader/core/loadable.rb', line 29

def n1_loader(name)
  name = n1_loader_name(name)

  send("#{name}_loader")
end

#n1_loader_set(name, loader_collection) ⇒ Object



35
36
37
38
39
# File 'lib/n1_loader/core/loadable.rb', line 35

def n1_loader_set(name, loader_collection)
  name = n1_loader_name(name)

  send("#{name}_loader=", loader_collection)
end