Class: AASM::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/aasm/state_machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ StateMachine

Returns a new instance of StateMachine.



7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#configObject

the following four methods provide the storage of all state machines



5
6
7
# File 'lib/aasm/state_machine.rb', line 5

def config
  @config
end

#eventsObject

the following four methods provide the storage of all state machines



5
6
7
# File 'lib/aasm/state_machine.rb', line 5

def events
  @events
end

#global_callbacksObject

the following four methods provide the storage of all state machines



5
6
7
# File 'lib/aasm/state_machine.rb', line 5

def global_callbacks
  @global_callbacks
end

#initial_stateObject

the following four methods provide the storage of all state machines



5
6
7
# File 'lib/aasm/state_machine.rb', line 5

def initial_state
  @initial_state
end

#nameObject

the following four methods provide the storage of all state machines



5
6
7
# File 'lib/aasm/state_machine.rb', line 5

def name
  @name
end

#statesObject

the following four methods provide the storage of all state machines



5
6
7
# File 'lib/aasm/state_machine.rb', line 5

def states
  @states
end

Instance Method Details

#add_event(name, options, &block) ⇒ Object



34
35
36
# 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) ⇒ Object



38
39
40
41
42
43
44
# 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) ⇒ Object



25
26
27
28
29
30
31
32
# 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) ⇒ Object

called internally by Ruby 1.9 after clone()



17
18
19
20
21
22
23
# 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