class AASM::StateMachine
def add_event(name, options, &block)
def add_event(name, options, &block) @events[name] = AASM::Core::Event.new(name, self, options, &block) end
def add_global_callbacks(name, *callbacks, &block)
def add_global_callbacks(name, *callbacks, &block) @global_callbacks[name] ||= [] callbacks.each do |callback| @global_callbacks[name] << callback unless @global_callbacks[name].include? callback end @global_callbacks[name] << block if block end
def add_state(state_name, klass, options)
def add_state(state_name, klass, options) set_initial_state(state_name, options) # allow reloading, extending or redefining a state @states.delete(state_name) if @states.include?(state_name) @states << AASM::Core::State.new(state_name, klass, self, options) end
def initialize(name)
def initialize(name) @initial_state = nil @states = [] @events = {} @global_callbacks = {} @config = AASM::Configuration.new @name = name end
def initialize_copy(orig)
def initialize_copy(orig) super @states = orig.states.collect { |state| state.clone } @events = {} orig.events.each_pair { |name, event| @events[name] = event.clone } @global_callbacks = @global_callbacks.dup end
def set_initial_state(name, options)
def set_initial_state(name, options) @initial_state = name if options[:initial] || !initial_state end