lib/batch_loader/executor_proxy.rb in batch-loader-1.0.4 vs lib/batch_loader/executor_proxy.rb in batch-loader-1.1.0
- old
+ new
@@ -2,13 +2,14 @@
require_relative "./executor"
class BatchLoader
class ExecutorProxy
- attr_reader :block, :global_executor
+ attr_reader :default_value, :block, :global_executor
- def initialize(&block)
+ def initialize(default_value, &block)
+ @default_value = default_value
@block = block
@block_hash_key = block.source_location
@global_executor = BatchLoader::Executor.ensure_current
end
@@ -27,10 +28,14 @@
def load(item:, value:)
loaded[item] = value
end
def loaded_value(item:)
- loaded[item]
+ if value_loaded?(item: item)
+ loaded[item]
+ else
+ @default_value.dup
+ end
end
def value_loaded?(item:)
loaded.key?(item)
end