Class: Omnitest::Skeptic::TestTransitions::FSM Private

Inherits:
Object
  • Object
show all
Defined in:
lib/omnitest/skeptic/test_transitions.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.

The simplest finite state machine pseudo-implementation needed to manage an Instance.

Constant Summary collapse

TRANSITIONS =

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.

[:clear, :detect, :exec, :verify]

Class Method Summary collapse

Class Method Details

.actions(last = nil, desired) ⇒ Array<Symbol>

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 an Array of all transitions to bring an Instance from its last reported transistioned state into the desired transitioned state.

Parameters:

  • last (String, Symbol, nil) (defaults to: nil)

    the last known transitioned state of the Instance, defaulting to ‘nil` (for unknown or no history)

  • desired (String, Symbol)

    the desired transitioned state for the Instance

Returns:

  • (Array<Symbol>)

    an Array of transition actions to perform



144
145
146
147
148
149
150
151
152
153
# File 'lib/omnitest/skeptic/test_transitions.rb', line 144

def self.actions(last = nil, desired)
  last_index = index(last)
  desired_index = index(desired)

  if last_index == desired_index || last_index > desired_index
    Array(TRANSITIONS[desired_index])
  else
    TRANSITIONS.slice(last_index + 1, desired_index - last_index)
  end
end

.index(transition) ⇒ 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.

Determines the index of a state in the state lifecycle vector. Woah.

Parameters:

  • transition (Symbol, #to_sym)

    a state

  • the (Integer)

    index position



162
163
164
165
166
167
168
# File 'lib/omnitest/skeptic/test_transitions.rb', line 162

def self.index(transition)
  if transition.nil?
    0
  else
    TRANSITIONS.find_index { |t| t == transition.to_sym }
  end
end