Class: Railsmith::Pipeline::StepDefinition

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def action
  @action
end

#conditionObject

Returns the value of attribute condition

Returns:

  • (Object)

    the current value of condition



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def condition
  @condition
end

#inputsObject

Returns the value of attribute inputs

Returns:

  • (Object)

    the current value of inputs



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def inputs
  @inputs
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def name
  @name
end

#on_failure_continueObject

Returns the value of attribute on_failure_continue

Returns:

  • (Object)

    the current value of on_failure_continue



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def on_failure_continue
  @on_failure_continue
end

#polarityObject

Returns the value of attribute polarity

Returns:

  • (Object)

    the current value of polarity



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def polarity
  @polarity
end

#rollbackObject

Returns the value of attribute rollback

Returns:

  • (Object)

    the current value of rollback



19
20
21
# File 'lib/railsmith/pipeline/step_definition.rb', line 19

def rollback
  @rollback
end

#serviceObject

Returns the value of attribute service

Returns:

  • (Object)

    the current value of 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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (Boolean)


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