class Kitchen::Instance::FSM

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

@api private @author Fletcher Nichol <fnichol@nichol.ca>

Constants

TRANSITIONS

Public Class Methods

actions(last = nil, desired) click to toggle source

Returns an Array of all transitions to bring an Instance from its last reported transistioned state into the desired transitioned state.

@param last [String,Symbol,nil] the last known transitioned state of

the Instance, defaulting to `nil` (for unknown or no history)

@param desired [String,Symbol] the desired transitioned state for the

Instance

@return [Array<Symbol>] an Array of transition actions to perform @api private

# File lib/kitchen/instance.rb, line 699
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) click to toggle source

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

@param transition [Symbol,#to_sym] a state @param [Integer] the index position @api private

# File lib/kitchen/instance.rb, line 717
def self.index(transition)
  if transition.nil?
    0
  else
    TRANSITIONS.find_index { |t| t == transition.to_sym }
  end
end