Class: MARS::ExecutionContext

Inherits:
Object
  • Object
show all
Defined in:
lib/mars/execution_context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: nil, global_state: {}) ⇒ ExecutionContext

Returns a new instance of ExecutionContext.



8
9
10
11
12
# File 'lib/mars/execution_context.rb', line 8

def initialize(input: nil, global_state: {})
  @current_input = input
  @outputs = {}
  @global_state = global_state
end

Instance Attribute Details

#current_inputObject

Returns the value of attribute current_input.



6
7
8
# File 'lib/mars/execution_context.rb', line 6

def current_input
  @current_input
end

#global_stateObject (readonly)

Returns the value of attribute global_state.



5
6
7
# File 'lib/mars/execution_context.rb', line 5

def global_state
  @global_state
end

#outputsObject (readonly)

Returns the value of attribute outputs.



5
6
7
# File 'lib/mars/execution_context.rb', line 5

def outputs
  @outputs
end

Instance Method Details

#[](step_name) ⇒ Object



14
15
16
# File 'lib/mars/execution_context.rb', line 14

def [](step_name)
  outputs[step_name.to_sym]
end

#fork(input: current_input, state: {}) ⇒ Object



23
24
25
# File 'lib/mars/execution_context.rb', line 23

def fork(input: current_input, state: {})
  self.class.new(input: input, global_state: global_state.merge(state))
end

#merge(child_contexts) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/mars/execution_context.rb', line 27

def merge(child_contexts)
  child_contexts.each do |child|
    @outputs.merge!(child.outputs)
  end

  self
end

#record(step_name, output) ⇒ Object



18
19
20
21
# File 'lib/mars/execution_context.rb', line 18

def record(step_name, output)
  @outputs[step_name.to_sym] = output
  @current_input = output
end