Module: Flowy::Concern
- Includes:
- StepRunner
- Defined in:
- lib/flowy/concern.rb,
lib/flowy/concern/step_runner.rb
Defined Under Namespace
Modules: ClassMethods, StepRunner
Class Attribute Summary collapse
-
._flowy_global_after_hooks ⇒ Object
readonly
Returns the value of attribute _flowy_global_after_hooks.
-
._flowy_global_around_hooks ⇒ Object
readonly
Returns the value of attribute _flowy_global_around_hooks.
-
._flowy_global_before_hooks ⇒ Object
readonly
Returns the value of attribute _flowy_global_before_hooks.
Class Method Summary collapse
- ._build_step_def(name, **overrides) ⇒ Object
-
.after_step(&block) ⇒ Object
Block signature: |step_name, result|.
-
.around_step(&block) ⇒ Object
Block signature: |step_name, previous_result, &call|.
-
.before_step(&block) ⇒ Object
Block signature: |step_name, previous_result|.
- .clear_global_hooks! ⇒ Object
- .included(base) ⇒ Object
Instance Method Summary collapse
- #failure(**kwargs) ⇒ Object
- #run_steps(starting_data: {}, steps: nil, rescue_errors: false) ⇒ Object
- #success(**kwargs) ⇒ Object
Class Attribute Details
._flowy_global_after_hooks ⇒ Object (readonly)
Returns the value of attribute _flowy_global_after_hooks.
10 11 12 |
# File 'lib/flowy/concern.rb', line 10 def _flowy_global_after_hooks @_flowy_global_after_hooks end |
._flowy_global_around_hooks ⇒ Object (readonly)
Returns the value of attribute _flowy_global_around_hooks.
10 11 12 |
# File 'lib/flowy/concern.rb', line 10 def _flowy_global_around_hooks @_flowy_global_around_hooks end |
._flowy_global_before_hooks ⇒ Object (readonly)
Returns the value of attribute _flowy_global_before_hooks.
10 11 12 |
# File 'lib/flowy/concern.rb', line 10 def _flowy_global_before_hooks @_flowy_global_before_hooks end |
Class Method Details
._build_step_def(name, **overrides) ⇒ Object
50 51 52 |
# File 'lib/flowy/concern.rb', line 50 def self._build_step_def(name, **overrides) DEFAULT_STEP_DEF.merge(name: name, **overrides) end |
.after_step(&block) ⇒ Object
Block signature: |step_name, result|
29 30 31 |
# File 'lib/flowy/concern.rb', line 29 def after_step(&block) @_flowy_global_after_hooks << block end |
.around_step(&block) ⇒ Object
Block signature: |step_name, previous_result, &call|
19 20 21 |
# File 'lib/flowy/concern.rb', line 19 def around_step(&block) @_flowy_global_around_hooks << block end |
.before_step(&block) ⇒ Object
Block signature: |step_name, previous_result|
24 25 26 |
# File 'lib/flowy/concern.rb', line 24 def before_step(&block) @_flowy_global_before_hooks << block end |
.clear_global_hooks! ⇒ Object
33 34 35 36 37 |
# File 'lib/flowy/concern.rb', line 33 def clear_global_hooks! @_flowy_global_around_hooks = [] @_flowy_global_before_hooks = [] @_flowy_global_after_hooks = [] end |
.included(base) ⇒ Object
14 15 16 |
# File 'lib/flowy/concern.rb', line 14 def included(base) base.extend(ClassMethods) end |
Instance Method Details
#failure(**kwargs) ⇒ Object
128 129 130 |
# File 'lib/flowy/concern.rb', line 128 def failure(**kwargs) self.class.failure(**kwargs) end |
#run_steps(starting_data: {}, steps: nil, rescue_errors: false) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/flowy/concern.rb', line 132 def run_steps(starting_data: {}, steps: nil, rescue_errors: false) initial = success(data: starting_data) step_list = steps ? steps.map { |s| Flowy::Concern._build_step_def(s) } : self.class._flowy_steps step_list.reduce(initial) do |current_result, step_def| break current_result if current_result.failure? call_step_with_hooks(step_def, current_result, rescue_errors: rescue_errors) end end |
#success(**kwargs) ⇒ Object
124 125 126 |
# File 'lib/flowy/concern.rb', line 124 def success(**kwargs) self.class.success(**kwargs) end |