2008-06-22 11:17:12 -04:00
|
|
|
require 'ostruct'
|
|
|
|
|
2008-05-31 15:27:15 -07:00
|
|
|
module AASM
|
|
|
|
class StateMachine
|
2008-06-01 14:12:57 -07:00
|
|
|
def self.[](*args)
|
|
|
|
(@machines ||= {})[args]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.[]=(*args)
|
|
|
|
val = args.pop
|
|
|
|
(@machines ||= {})[args] = val
|
|
|
|
end
|
|
|
|
|
2008-06-22 11:17:12 -04:00
|
|
|
attr_accessor :states, :events, :initial_state, :config
|
2008-05-31 15:27:15 -07:00
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
|
|
|
@initial_state = nil
|
|
|
|
@states = []
|
2008-05-31 15:37:22 -07:00
|
|
|
@events = {}
|
2008-06-22 11:17:12 -04:00
|
|
|
@config = OpenStruct.new
|
2008-05-31 15:27:15 -07:00
|
|
|
end
|
2008-05-31 15:33:17 -07:00
|
|
|
|
2008-11-05 11:06:36 -05:00
|
|
|
def clone
|
|
|
|
klone = super
|
|
|
|
klone.states = states.clone
|
|
|
|
klone
|
|
|
|
end
|
|
|
|
|
2008-05-31 15:33:17 -07:00
|
|
|
def create_state(name, options)
|
|
|
|
@states << AASM::SupportingClasses::State.new(name, options) unless @states.include?(name)
|
|
|
|
end
|
2008-05-31 15:27:15 -07:00
|
|
|
end
|
|
|
|
end
|