Class: Kitchen::Instance::FSM

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/instance.rb

Overview

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

Author:

Class Method Summary collapse

Class Method Details

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

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



342
343
344
345
346
347
348
349
350
351
# File 'lib/kitchen/instance.rb', line 342

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