Class: MARS::Workflows::Sequential

Inherits:
Runnable
  • Object
show all
Defined in:
lib/mars/workflows/sequential.rb

Instance Attribute Summary

Attributes inherited from Runnable

#formatter, #name, #state

Instance Method Summary collapse

Methods inherited from Runnable

formatter, step_name

Methods included from Hooks

included, #run_after_hooks, #run_before_hooks

Constructor Details

#initialize(name, steps:, **kwargs) ⇒ Sequential

Returns a new instance of Sequential.



6
7
8
9
10
# File 'lib/mars/workflows/sequential.rb', line 6

def initialize(name, steps:, **kwargs)
  super(name: name, **kwargs)

  @steps = steps
end

Instance Method Details

#run(context) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mars/workflows/sequential.rb', line 12

def run(context)
  context = ensure_context(context)

  @steps.each do |step|
    step.run_before_hooks(context)

    step_input = step.formatter.format_input(context)
    context.current_input = step_input

    result = step.run(context)

    formatted = step.formatter.format_output(result)
    context.record(step.name, formatted)
    step.run_after_hooks(context, formatted)
  end

  context.current_input
end