# 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
# File lib/deltacloud/models/state_machine.rb, line 33 def finish() state(:finish) end
# File lib/deltacloud/models/state_machine.rb, line 57 def method_missing(sym,*args) return state( sym ) if ( args.empty? ) super( sym, *args ) end
# File lib/deltacloud/models/state_machine.rb, line 29 def start() state(:start) end
# 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
# File lib/deltacloud/models/state_machine.rb, line 53 def valid_action_name?(name) @all_actions.nil? || @all_actions.include?(name.to_sym) end
# File lib/deltacloud/models/state_machine.rb, line 49 def valid_state_name?(name) @all_states.nil? || @all_states.include?(name.to_sym) end