class EXEL::DeferredContextValue
When context
is referenced in a job definition, an instance of DeferredContextValue
will be put in its place. At runtime, the first time a DeferredContextValue
is read via {EXEL::Context#[]}, it will be replaced by the value it was referring to.
Example:
process with: MyProcessor, foo: context[:bar]
Attributes
Public Class Methods
# File lib/exel/deferred_context_value.rb, line 38 def initialize @keys = [] end
If value
is an instance of DeferredContextValue
, it will be resolved to its actual value in the context. If it is an Array
or Hash
all DeferredContextValue
instances within it will be resolved. If it is anything else, it will just be returned.
@return value, with all DeferredContextValue
instances resolved
# File lib/exel/deferred_context_value.rb, line 19 def resolve(value, context) if deferred?(value) value = value.get(context) elsif value.is_a?(Array) value.map! { |v| resolve(v, context) } elsif value.is_a?(Hash) value.each { |k, v| value[k] = resolve(v, context) } end value end
Private Class Methods
# File lib/exel/deferred_context_value.rb, line 33 def deferred?(value) value.is_a?(DeferredContextValue) end
Public Instance Methods
Records the keys that will be used to lookup the value from the context at runtime. Supports nested hashes such as:
context[:hash1][:hash2][:key]
# File lib/exel/deferred_context_value.rb, line 45 def [](key) keys << key self end
Given a context, returns the value that this instance was acting as a placeholder for.
# File lib/exel/deferred_context_value.rb, line 51 def get(context) keys.reduce(context) { |acc, elem| acc[elem] } end