Class: AASM::StateMachine

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ StateMachine

Returns a new instance of StateMachine.



17
18
19
20
21
22
23
24
# File 'lib/state_machine.rb', line 17

def initialize(name)
  @name   = name
  @initial_state = nil
  @states = []
  @events = {}
  @config = OpenStruct.new
  @integers = AASM::SupportingClasses::Integers.new
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



14
15
16
# File 'lib/state_machine.rb', line 14

def config
  @config
end

#eventsObject

Returns the value of attribute events.



14
15
16
# File 'lib/state_machine.rb', line 14

def events
  @events
end

#initial_stateObject

Returns the value of attribute initial_state.



14
15
16
# File 'lib/state_machine.rb', line 14

def initial_state
  @initial_state
end

#integersObject

Returns the value of attribute integers.



14
15
16
# File 'lib/state_machine.rb', line 14

def integers
  @integers
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/state_machine.rb', line 15

def name
  @name
end

#statesObject

Returns the value of attribute states.



14
15
16
# File 'lib/state_machine.rb', line 14

def states
  @states
end

Class Method Details

.[](*args) ⇒ Object



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

def self.[](*args)
  (@machines ||= {})[args]
end

.[]=(*args) ⇒ Object



9
10
11
12
# File 'lib/state_machine.rb', line 9

def self.[]=(*args)
  val = args.pop
  (@machines ||= {})[args] = val
end

Instance Method Details

#cloneObject



26
27
28
29
30
# File 'lib/state_machine.rb', line 26

def clone
  klone = super
  klone.states = states.clone
  klone
end

#create_state(name, options) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/state_machine.rb', line 32

def create_state(name, options)
  unless @states.include?(name)
    state = AASM::SupportingClasses::State.new(name, options) 
    @states << state
    integers.add_integer(state) if state.options[:integer]
  end
end