class Deltacloud::StateMachine

Attributes

states[R]

Public Class Methods

new(opts={}, &block) click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 22
def initialize(opts={}, &block)
  @all_states = opts[:all_states]
  @all_actions = opts[:all_actions]
  @states  = []
  instance_eval &block if block
end

Public Instance Methods

finish() click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 33
def finish()
  state(:finish)
end
method_missing(sym,*args) click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 57
def method_missing(sym,*args)
  return state( sym ) if ( args.empty? )
  super( sym, *args )
end
start() click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 29
def start()
  state(:start)
end
state(name) click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 37
def state(name)
  unless valid_state_name?(name)
    raise "State '#{name}' not in list of allowed states"
  end
  state = @states.find{|e| e.name == name.to_sym}
  if ( state.nil? )
    state = State.new( self, name.to_sym )
    @states << state
  end
  state
end
valid_action_name?(name) click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 53
def valid_action_name?(name)
  @all_actions.nil? || @all_actions.include?(name.to_sym)
end
valid_state_name?(name) click to toggle source
# File lib/deltacloud/models/state_machine.rb, line 49
def valid_state_name?(name)
  @all_states.nil? || @all_states.include?(name.to_sym)
end