Class: N1Loader::LoaderCollection

Inherits:
Object
  • Object
show all
Includes:
ArLazyPreload::LoaderCollectionPatch
Defined in:
lib/n1_loader/core/loader_collection.rb

Overview

The class is used for storing collections of loaders for elements per set of arguments.

Instance Attribute Summary collapse

Attributes included from ArLazyPreload::LoaderCollectionPatch

#context_setup

Instance Method Summary collapse

Constructor Details

#initialize(loader_class, elements) ⇒ LoaderCollection

Returns a new instance of LoaderCollection.



8
9
10
11
# File 'lib/n1_loader/core/loader_collection.rb', line 8

def initialize(loader_class, elements)
  @loader_class = loader_class
  @elements = elements
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



6
7
8
# File 'lib/n1_loader/core/loader_collection.rb', line 6

def elements
  @elements
end

#loader_classObject (readonly)

Returns the value of attribute loader_class.



6
7
8
# File 'lib/n1_loader/core/loader_collection.rb', line 6

def loader_class
  @loader_class
end

Instance Method Details

#with(**args) ⇒ Object



13
14
15
16
17
# File 'lib/n1_loader/core/loader_collection.rb', line 13

def with(**args)
  loader = loader_class.new(elements, **args)

  loaders[loader.cache_key] ||= loader
end