Class: SimpleFlow::StepTracker
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- SimpleFlow::StepTracker
- Defined in:
- lib/simple_flow/step_tracker.rb
Overview
The StepTracker class serves as a wrapper around any callable object, typically representing a step in a workflow. Its primary purpose is to execute the wrapped object’s call method and then decide what to do based on the outcome. If the result of the call indicates that the process can continue, it simply returns the result. However, if the process should halt, it enriches the result with additional context before returning it.
This enables a mechanism for both executing steps in a workflow and conditionally handling situations where a step decides the flow should not continue. The enriched context can then be used downstream to understand why the flow was halted, and potentially take corrective action.
Example usage:
class ExampleStep
def call(result)
result.do_something
if result.success?
result.with_continue(true)
else
result.with_continue(false)
end
end
end
result = SomeResult.new
wrapped_step = SimpleFlow::StepTracker.new(ExampleStep.new)
final_result = wrapped_step.call(result)
if final_result.continue
# proceed with workflow
else
# handle halted workflow
end
Instance Method Summary collapse
-
#call(result) ⇒ Object
Calls the wrapped object’s call method with the given result.
Instance Method Details
#call(result) ⇒ Object
Calls the wrapped object’s call method with the given result. Depending on the outcome of this call, it either returns the result as-is (to continue the workflow) or enriches the result with context indicating that this particular step is where the workflow was halted.
52 53 54 55 |
# File 'lib/simple_flow/step_tracker.rb', line 52 def call(result) result = __getobj__.call(result) result.continue? ? result : result.with_context(:halted_step, __getobj__) end |