class Novel::Workflow
Constants
- FINISH_STEP
Attributes
activity_flow[R]
compensation_flow[R]
raw[R]
Public Class Methods
new(raw:)
click to toggle source
# File lib/novel/workflow.rb, line 7 def initialize(raw:) @raw = raw end
Public Instance Methods
activity_steps()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
calculate_compensation_index(step_name)
click to toggle source
# File lib/novel/workflow.rb, line 59 def calculate_compensation_index(step_name) compensation_flow.include?(step_name) ? compensation_flow.index(step_name) : activity_flow.reverse.index(step_name) end
get_next_by_index(list, step_index)
click to toggle source
# File lib/novel/workflow.rb, line 63 def get_next_by_index(list, step_index) next_index = step_index + 1 if next_index < list.count list[next_index] || get_next_by_index(list, step_index + 1) else FINISH_STEP end end