Class: EXEL::Context
- Inherits:
-
Hash
- Object
- Hash
- EXEL::Context
- Defined in:
- lib/exel/context.rb
Overview
The Context
is the shared memory of a running job. It acts as the source of input to processors and the place for them to store their outputs. It can be serialized and deserialized to support remote execution.
Class Method Summary collapse
-
.deserialize(uri) ⇒ Context
Given a string representing the URI to a serialized context, downloads and returns the deserialized context.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value referenced by the given key.
-
#deep_dup ⇒ Context
Returns a deep copy of this context.
- #fetch(key) ⇒ Object
-
#initialize(initial_context = {}) ⇒ Context
constructor
Accepts an optional hash of keys and values to initialize the context with.
-
#serialize ⇒ String
Serializes this instance to a local file and uses the remote provider to upload it.
Constructor Details
#initialize(initial_context = {}) ⇒ Context
Accepts an optional hash of keys and values to initialize the context with.
11 12 13 14 |
# File 'lib/exel/context.rb', line 11 def initialize(initial_context = {}) super() merge!(initial_context) end |
Class Method Details
.deserialize(uri) ⇒ Context
Given a string representing the URI to a serialized context, downloads and returns the deserialized context
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/exel/context.rb', line 34 def self.deserialize(uri) file = EXEL::Value.localize(uri) begin context = Marshal.load(file.read) # rubocop:disable Airbnb/UnsafeYamlMarshal ensure file.close end context end |
Instance Method Details
#[](key) ⇒ Object
Returns the value referenced by the given key. If it is a remote value, it will be converted to a local value and the local value will be returned.
48 49 50 |
# File 'lib/exel/context.rb', line 48 def [](key) convert_value!(key, super(key)) end |
#deep_dup ⇒ Context
Returns a deep copy of this context. The copy and the original will have no shared object references.
19 20 21 |
# File 'lib/exel/context.rb', line 19 def deep_dup Context.deserialize(serialize) end |
#fetch(key) ⇒ Object
52 53 54 |
# File 'lib/exel/context.rb', line 52 def fetch(key) convert_value!(key, super(key)) end |