Class: BatchLoader::ExecutorProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_loader/executor_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_value, key, &block) ⇒ ExecutorProxy

Returns a new instance of ExecutorProxy.



9
10
11
12
13
14
# File 'lib/batch_loader/executor_proxy.rb', line 9

def initialize(default_value, key, &block)
  @default_value = default_value
  @block = block
  @block_hash_key = [block.source_location, key]
  @global_executor = BatchLoader::Executor.ensure_current
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/batch_loader/executor_proxy.rb', line 7

def block
  @block
end

#default_valueObject (readonly)

Returns the value of attribute default_value.



7
8
9
# File 'lib/batch_loader/executor_proxy.rb', line 7

def default_value
  @default_value
end

#global_executorObject (readonly)

Returns the value of attribute global_executor.



7
8
9
# File 'lib/batch_loader/executor_proxy.rb', line 7

def global_executor
  @global_executor
end

Instance Method Details

#add(item:) ⇒ Object



16
17
18
# File 'lib/batch_loader/executor_proxy.rb', line 16

def add(item:)
  items_to_load << item
end

#delete(items:) ⇒ Object



24
25
26
# File 'lib/batch_loader/executor_proxy.rb', line 24

def delete(items:)
  global_executor.items_by_block[@block_hash_key] = items_to_load - items
end

#list_itemsObject



20
21
22
# File 'lib/batch_loader/executor_proxy.rb', line 20

def list_items
  items_to_load.to_a.freeze
end

#load(item:, value:) ⇒ Object



28
29
30
# File 'lib/batch_loader/executor_proxy.rb', line 28

def load(item:, value:)
  loaded[item] = value
end

#loaded_value(item:) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/batch_loader/executor_proxy.rb', line 32

def loaded_value(item:)
  if value_loaded?(item: item)
    loaded[item]
  else
    @default_value.dup
  end
end

#unload_value(item:) ⇒ Object



44
45
46
# File 'lib/batch_loader/executor_proxy.rb', line 44

def unload_value(item:)
  loaded.delete(item)
end

#value_loaded?(item:) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/batch_loader/executor_proxy.rb', line 40

def value_loaded?(item:)
  loaded.key?(item)
end