Class: Novel::Workflow
- Inherits:
-
Object
- Object
- Novel::Workflow
- Defined in:
- lib/novel/workflow.rb
Constant Summary collapse
- FINISH_STEP =
:finish
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #activity_steps ⇒ Object
- #activity_steps_from(step) ⇒ Object
- #compensation_steps ⇒ Object
- #compensation_steps_from(step) ⇒ Object
-
#initialize(raw:) ⇒ Workflow
constructor
A new instance of Workflow.
- #next_activity_step(step_name) ⇒ Object
- #next_compensation_step(step_name) ⇒ Object
Constructor Details
#initialize(raw:) ⇒ Workflow
Returns a new instance of Workflow.
7 8 9 |
# File 'lib/novel/workflow.rb', line 7 def initialize(raw:) @raw = raw end |
Instance Attribute Details
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
3 4 5 |
# File 'lib/novel/workflow.rb', line 3 def raw @raw end |
Instance Method Details
#activity_steps ⇒ Object
11 12 13 |
# File 'lib/novel/workflow.rb', line 11 def activity_steps @activity_steps ||= raw.map { |step| { name: step[:name], async: step[:activity][:async] } } end |
#activity_steps_from(step) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/novel/workflow.rb', line 15 def activity_steps_from(step) if step next_step_index = activity_flow.index(step) + 1 remaining_steps = activity_flow[next_step_index..-1] activity_steps.select { |s, _| remaining_steps.include?(s[:name]) } else activity_steps end end |
#compensation_steps ⇒ Object
25 26 27 |
# File 'lib/novel/workflow.rb', line 25 def compensation_steps @compensation_steps ||= raw.reverse.map { |step| step[:compensation] ? { name: step[:name], async: step[:compensation][:async] } : nil }.compact end |
#compensation_steps_from(step) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/novel/workflow.rb', line 29 def compensation_steps_from(step) # TODO: question should I call compensation logic for failed step or should I call next step in the flow? first_compensation_step_index = calculate_compensation_index(next_compensation_step(step)[:name]) remaining_steps = compensation_flow[first_compensation_step_index..-1] compensation_steps.select { |s, _| remaining_steps.include?(s[:name]) } end |
#next_activity_step(step_name) ⇒ Object
38 39 40 41 42 |
# File 'lib/novel/workflow.rb', line 38 def next_activity_step(step_name) # activity_flow.include?(step_name) activity_steps.find { |s| s[:name] == get_next_by_index(activity_flow, activity_flow.index(step_name)) } end |
#next_compensation_step(step_name) ⇒ Object
44 45 46 47 48 |
# File 'lib/novel/workflow.rb', line 44 def next_compensation_step(step_name) # activity_flow.include?(step_name) compensation_steps.find { |s| s[:name] == get_next_by_index(compensation_flow, calculate_compensation_index(step_name)) } end |