Class: AASM::StateMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/aasm/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.



14
15
16
17
18
19
20
# File 'lib/aasm/state_machine.rb', line 14

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

Instance Attribute Details

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/aasm/state_machine.rb', line 11

def config
  @config
end

#eventsObject

Returns the value of attribute events.



11
12
13
# File 'lib/aasm/state_machine.rb', line 11

def events
  @events
end

#initial_stateObject

Returns the value of attribute initial_state.



11
12
13
# File 'lib/aasm/state_machine.rb', line 11

def initial_state
  @initial_state
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/aasm/state_machine.rb', line 12

def name
  @name
end

#statesObject

Returns the value of attribute states.



11
12
13
# File 'lib/aasm/state_machine.rb', line 11

def states
  @states
end

Class Method Details

.[](*args) ⇒ Object



2
3
4
# File 'lib/aasm/state_machine.rb', line 2

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

.[]=(*args) ⇒ Object



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

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

Instance Method Details

#cloneObject



22
23
24
25
26
27
# File 'lib/aasm/state_machine.rb', line 22

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

#create_state(name, options) ⇒ Object



29
30
31
# File 'lib/aasm/state_machine.rb', line 29

def create_state(name, options)
  @states << AASM::SupportingClasses::State.new(name, options) unless @states.include?(name)
end