Class: BatchLoader::Executor
- Inherits:
-
Object
- Object
- BatchLoader::Executor
- Defined in:
- lib/batch_loader/executor.rb
Constant Summary collapse
- NAMESPACE =
:batch_loader
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(item, &batch_block) ⇒ Object
- #find(item, &batch_block) ⇒ Object
-
#initialize ⇒ Executor
constructor
A new instance of Executor.
- #items(&batch_block) ⇒ Object
- #save(item, loaded_item, &batch_block) ⇒ Object
- #saved?(&batch_block) ⇒ Boolean
Constructor Details
#initialize ⇒ Executor
Returns a new instance of Executor.
13 14 15 16 |
# File 'lib/batch_loader/executor.rb', line 13 def initialize @items_by_batch_block = Hash.new { |hash, key| hash[key] = [] } @loaded_items_by_batch_block = Hash.new { |hash, key| hash[key] = {} } end |
Class Method Details
.clear_current ⇒ Object
9 10 11 |
# File 'lib/batch_loader/executor.rb', line 9 def self.clear_current Thread.current[NAMESPACE] = nil end |
.ensure_current ⇒ Object
5 6 7 |
# File 'lib/batch_loader/executor.rb', line 5 def self.ensure_current Thread.current[NAMESPACE] = Thread.current[NAMESPACE] || new end |
Instance Method Details
#add_item(item, &batch_block) ⇒ Object
18 19 20 |
# File 'lib/batch_loader/executor.rb', line 18 def add_item(item, &batch_block) @items_by_batch_block[batch_block.source_location] << item end |
#find(item, &batch_block) ⇒ Object
34 35 36 |
# File 'lib/batch_loader/executor.rb', line 34 def find(item, &batch_block) @loaded_items_by_batch_block.dig(batch_block.source_location, item) end |
#items(&batch_block) ⇒ Object
22 23 24 |
# File 'lib/batch_loader/executor.rb', line 22 def items(&batch_block) @items_by_batch_block[batch_block.source_location] end |
#save(item, loaded_item, &batch_block) ⇒ Object
26 27 28 |
# File 'lib/batch_loader/executor.rb', line 26 def save(item, loaded_item, &batch_block) @loaded_items_by_batch_block[batch_block.source_location][item] = loaded_item end |
#saved?(&batch_block) ⇒ Boolean
30 31 32 |
# File 'lib/batch_loader/executor.rb', line 30 def saved?(&batch_block) @loaded_items_by_batch_block.key?(batch_block.source_location) end |