Module: Dry::Workflow::Mixin
- Defined in:
- lib/dry/workflow.rb
Overview
The main mixin to be included in classes that define workflows.
Instance Attribute Summary collapse
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#workflow_instance_methods_module ⇒ Object
readonly
Returns the value of attribute workflow_instance_methods_module.
Class Method Summary collapse
Instance Method Summary collapse
-
#map(step_name, with: nil, **options) ⇒ void
Defines a ‘map’ step, which is expected to transform the input and always succeed.
-
#step(step_name, with: nil, rollback: nil, **options) ⇒ void
Defines a standard step in the workflow.
-
#try(step_name, with: nil, rollback: nil, catch_exception: StandardError, **options) ⇒ void
Defines a ‘try’ step that catches exceptions and wraps the result in a Result monad.
Instance Attribute Details
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
22 23 24 |
# File 'lib/dry/workflow.rb', line 22 def steps @steps end |
#workflow_instance_methods_module ⇒ Object (readonly)
Returns the value of attribute workflow_instance_methods_module.
22 23 24 |
# File 'lib/dry/workflow.rb', line 22 def workflow_instance_methods_module @workflow_instance_methods_module end |
Class Method Details
.extended(base) ⇒ Object
16 17 18 19 20 |
# File 'lib/dry/workflow.rb', line 16 def self.extended(base) base.instance_variable_set(:@steps, []) base.instance_variable_set(:@workflow_instance_methods_module, Module.new) base.include base.instance_variable_get(:@workflow_instance_methods_module) end |
Instance Method Details
#map(step_name, with: nil, **options) ⇒ void
This method returns an undefined value.
Defines a ‘map’ step, which is expected to transform the input and always succeed. Rollbacks are typically not defined for map steps.
66 67 68 69 70 71 72 73 74 |
# File 'lib/dry/workflow.rb', line 66 def map(step_name, with: nil, **) define_workflow_step( name: step_name, type: :map, operation_source: with || step_name, rollback_source: nil, # Maps typically don't have rollbacks options: ) end |
#step(step_name, with: nil, rollback: nil, **options) ⇒ void
This method returns an undefined value.
Defines a standard step in the workflow.
31 32 33 34 35 36 37 38 39 |
# File 'lib/dry/workflow.rb', line 31 def step(step_name, with: nil, rollback: nil, **) define_workflow_step( name: step_name, type: :step, operation_source: with || step_name, rollback_source: rollback, options: ) end |
#try(step_name, with: nil, rollback: nil, catch_exception: StandardError, **options) ⇒ void
This method returns an undefined value.
Defines a ‘try’ step that catches exceptions and wraps the result in a Result monad.
49 50 51 52 53 54 55 56 57 |
# File 'lib/dry/workflow.rb', line 49 def try(step_name, with: nil, rollback: nil, catch_exception: StandardError, **) define_workflow_step( name: step_name, type: :try, operation_source: with || step_name, rollback_source: rollback, options: .merge(catch_exception: catch_exception) ) end |