Class: Railsmith::Pipeline::StepDefinition
- Inherits:
-
Struct
- Object
- Struct
- Railsmith::Pipeline::StepDefinition
- Defined in:
- lib/railsmith/pipeline/step_definition.rb
Overview
Immutable record describing a single declared pipeline step.
name - symbolic identifier used in instrumentation and error messages service - a BaseService subclass (the class itself, not an instance) action - the action symbol to invoke on that service inputs - optional Hash of { target_key => source_key } renames applied to
accumulated params before they are forwarded to this step's service;
raises ParamMappingError when a source_key is absent
rollback - optional Symbol (action name on service) or Proc invoked when a later
step fails; used to undo this step's side-effects
condition - optional Symbol (named guard) or Proc evaluated against
(accumulated_params, context); combined with polarity to decide skip
polarity - :if (run when condition is truthy) or :unless (run when falsy) on_failure_continue - when true, a failure from this step does not halt the pipeline
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#on_failure_continue ⇒ Object
Returns the value of attribute on_failure_continue.
-
#polarity ⇒ Object
Returns the value of attribute polarity.
-
#rollback ⇒ Object
Returns the value of attribute rollback.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
-
#continue_on_failure? ⇒ Boolean
rubocop:enable Naming/PredicatePrefix.
-
#has_rollback? ⇒ Boolean
rubocop:disable Naming/PredicatePrefix – public name used in docs/specs.
-
#resolve_params(accumulated) ⇒ Object
Resolve the params to pass to this step’s service.
- #rollback? ⇒ Boolean
-
#skip?(accumulated_params, context, guards = {}) ⇒ Boolean
Returns true when this step should be skipped for the given execution context.
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def action @action end |
#condition ⇒ Object
Returns the value of attribute condition
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def condition @condition end |
#inputs ⇒ Object
Returns the value of attribute inputs
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def inputs @inputs end |
#name ⇒ Object
Returns the value of attribute name
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def name @name end |
#on_failure_continue ⇒ Object
Returns the value of attribute on_failure_continue
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def on_failure_continue @on_failure_continue end |
#polarity ⇒ Object
Returns the value of attribute polarity
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def polarity @polarity end |
#rollback ⇒ Object
Returns the value of attribute rollback
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def rollback @rollback end |
#service ⇒ Object
Returns the value of attribute service
19 20 21 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 19 def service @service end |
Instance Method Details
#continue_on_failure? ⇒ Boolean
rubocop:enable Naming/PredicatePrefix
34 35 36 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 34 def continue_on_failure? !!on_failure_continue end |
#has_rollback? ⇒ Boolean
rubocop:disable Naming/PredicatePrefix – public name used in docs/specs
29 30 31 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 29 def has_rollback? rollback? end |
#resolve_params(accumulated) ⇒ Object
Resolve the params to pass to this step’s service.
accumulated - the current accumulated params Hash
Returns a new Hash ready to be forwarded as params: to the service call. When inputs: is present, each { target => source } pair replaces source_key with target_key in the forwarded hash; the rest of accumulated passes through.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 57 def resolve_params(accumulated) return accumulated.dup if inputs.nil? || inputs.empty? result = accumulated.dup inputs.each do |target_key, source_key| raise Pipeline::ParamMappingError.new(name, source_key) unless result.key?(source_key) next if target_key == source_key result[target_key] = result.delete(source_key) end result end |
#rollback? ⇒ Boolean
24 25 26 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 24 def rollback? !rollback.nil? end |
#skip?(accumulated_params, context, guards = {}) ⇒ Boolean
Returns true when this step should be skipped for the given execution context.
accumulated_params - the current accumulated params Hash context - the pipeline’s Railsmith::Context guards - Hash of { name_sym => Proc } registered on the pipeline
43 44 45 46 47 48 |
# File 'lib/railsmith/pipeline/step_definition.rb', line 43 def skip?(accumulated_params, context, guards = {}) return false if condition.nil? raw = evaluate_condition(accumulated_params, context, guards) polarity == :if ? !raw : !!raw end |