class AASM::StateMachine

Attributes

config[RW]

the following four methods provide the storage of all state machines

events[RW]

the following four methods provide the storage of all state machines

global_callbacks[RW]

the following four methods provide the storage of all state machines

initial_state[RW]

the following four methods provide the storage of all state machines

name[RW]

the following four methods provide the storage of all state machines

states[RW]

the following four methods provide the storage of all state machines

Public Class Methods

new(name) click to toggle source
# File lib/aasm/state_machine.rb, line 7
def initialize(name)
  @initial_state = nil
  @states = []
  @events = {}
  @global_callbacks = {}
  @config = AASM::Configuration.new
  @name = name
end

Public Instance Methods

add_event(name, options, &block) click to toggle source
# File lib/aasm/state_machine.rb, line 34
def add_event(name, options, &block)
  @events[name] = AASM::Core::Event.new(name, self, options, &block)
end
add_global_callbacks(name, *callbacks, &block) click to toggle source
# File lib/aasm/state_machine.rb, line 38
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
add_state(state_name, klass, options) click to toggle source
# File lib/aasm/state_machine.rb, line 25
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
initialize_copy(orig) click to toggle source

called internally by Ruby 1.9 after clone()

Calls superclass method
# File lib/aasm/state_machine.rb, line 17
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

Private Instance Methods

set_initial_state(name, options) click to toggle source
# File lib/aasm/state_machine.rb, line 48
def set_initial_state(name, options)
  @initial_state = name if options[:initial] || !initial_state
end