Class: GenevaDrive::StepDefinition Private

Inherits:
Object
  • Object
show all
Defined in:
lib/geneva_drive/step_definition.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Metadata about a step definition in a workflow. Holds the step name, callable (block or method name), wait time, skip conditions, and exception handling configuration.

Constant Summary collapse

EXCEPTION_HANDLERS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Valid exception handler values

%i[pause! cancel! reattempt! skip!].freeze
NOT_SET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Sentinel value to distinguish "on_exception not provided" from "on_exception: :pause!"

Object.new.freeze
VALID_SKIP_CONDITION_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Valid types for skip conditions

[Symbol, Proc, TrueClass, FalseClass, NilClass].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, callable:, call_location: nil, block_location: nil, **options) ⇒ StepDefinition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new step definition.

Parameters:

  • name (String, Symbol)

    the step name

  • callable (Proc, Symbol, nil)

    the code to execute (block or method name)

  • options (Hash)

    additional options

  • call_location (Array<String, Integer>, nil) (defaults to: nil)

    source location where step was called

  • block_location (Array<String, Integer>, nil) (defaults to: nil)

    source location of the step block

Options Hash (**options):

  • :wait (ActiveSupport::Duration, nil)

    delay before execution

  • :skip_if (Proc, Symbol, Boolean, nil)

    condition for skipping

  • :if (Proc, Symbol, Boolean, nil)

    condition for running (inverse of skip_if)

  • :on_exception (Symbol, GenevaDrive::ExceptionPolicy, Proc, Array<GenevaDrive::ExceptionPolicy>)

    how to handle exceptions. An Array of ExceptionPolicy objects is wrapped in a CombinedExceptionPolicy that resolves specific policies first, then blanket fallback.

  • :max_reattempts (Integer, nil)

    max consecutive reattempts (symbol form only)

  • :before_step (String, Symbol, nil)

    position before this step

  • :after_step (String, Symbol, nil)

    position after this step

Raises:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/geneva_drive/step_definition.rb', line 62

def initialize(name:, callable:, call_location: nil, block_location: nil, **options)
  @name = name.to_s
  @callable = callable
  @call_location = call_location
  @block_location = block_location
  @wait = options[:wait]
  @skip_if_option = options[:skip_if]
  @if_option = options[:if]
  @skip_condition = @skip_if_option || @if_option
  @on_exception_raw = options.fetch(:on_exception, NOT_SET)
  @max_reattempts_raw = options[:max_reattempts]
  @max_reattempts_explicitly_set = options.key?(:max_reattempts)
  @terminal_action_raw = options[:terminal_action]
  @before_step = options[:before_step]&.to_s
  @after_step = options[:after_step]&.to_s

  validate!
  @exception_policy = build_exception_policy
end

Instance Attribute Details

#after_stepString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of step this should be placed after.

Returns:

  • (String, nil)

    name of step this should be placed after



37
38
39
# File 'lib/geneva_drive/step_definition.rb', line 37

def after_step
  @after_step
end

#before_stepString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of step this should be placed before.

Returns:

  • (String, nil)

    name of step this should be placed before



34
35
36
# File 'lib/geneva_drive/step_definition.rb', line 34

def before_step
  @before_step
end

#block_locationArray<String, Integer>? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns source location of the step block [path, lineno].

Returns:

  • (Array<String, Integer>, nil)

    source location of the step block [path, lineno]



43
44
45
# File 'lib/geneva_drive/step_definition.rb', line 43

def block_location
  @block_location
end

#call_locationArray<String, Integer>? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns source location where step was called [path, lineno].

Returns:

  • (Array<String, Integer>, nil)

    source location where step was called [path, lineno]



40
41
42
# File 'lib/geneva_drive/step_definition.rb', line 40

def call_location
  @call_location
end

#callableProc, Symbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the callable to execute (block or method name).

Returns:

  • (Proc, Symbol)

    the callable to execute (block or method name)



22
23
24
# File 'lib/geneva_drive/step_definition.rb', line 22

def callable
  @callable
end

#exception_policyGenevaDrive::ExceptionPolicy, GenevaDrive::CombinedExceptionPolicy (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns exception handling policy.

Returns:



31
32
33
# File 'lib/geneva_drive/step_definition.rb', line 31

def exception_policy
  @exception_policy
end

#nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the step name.

Returns:

  • (String)

    the step name



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

def name
  @name
end

#skip_conditionProc, ... (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns condition for skipping this step.

Returns:

  • (Proc, Symbol, Boolean, nil)

    condition for skipping this step



28
29
30
# File 'lib/geneva_drive/step_definition.rb', line 28

def skip_condition
  @skip_condition
end

#waitActiveSupport::Duration? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns wait time before executing this step.

Returns:

  • (ActiveSupport::Duration, nil)

    wait time before executing this step



25
26
27
# File 'lib/geneva_drive/step_definition.rb', line 25

def wait
  @wait
end

Instance Method Details

#execute_in_context(workflow) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Executes the step callable in the context of the workflow.

Parameters:

Returns:

  • (Object)

    the result of the step execution



113
114
115
116
117
118
119
# File 'lib/geneva_drive/step_definition.rb', line 113

def execute_in_context(workflow)
  if @callable.is_a?(Symbol)
    workflow.send(@callable)
  else
    workflow.instance_exec(&@callable)
  end
end

#max_reattemptsInteger?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the max_reattempts from the exception policy. Provided for backward compatibility with code that reads step_def.max_reattempts.

Returns:

  • (Integer, nil)


96
97
98
# File 'lib/geneva_drive/step_definition.rb', line 96

def max_reattempts
  @exception_policy&.max_reattempts
end

#on_exceptionSymbol?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the action symbol from the exception policy. Provided for backward compatibility with code that reads step_def.on_exception.

Returns:

  • (Symbol, nil)

    the action symbol, or nil for imperative/combined policies



86
87
88
89
90
# File 'lib/geneva_drive/step_definition.rb', line 86

def on_exception
  return nil unless @exception_policy
  return nil if @exception_policy.is_a?(GenevaDrive::CombinedExceptionPolicy)
  @exception_policy.action
end

#should_skip?(workflow) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Evaluates whether this step should be skipped for the given workflow.

Parameters:

Returns:

  • (Boolean)

    true if the step should be skipped



104
105
106
107
# File 'lib/geneva_drive/step_definition.rb', line 104

def should_skip?(workflow)
  return false unless @skip_condition
  evaluate_condition(@skip_condition, workflow)
end