Class: AASM::StateMachine
- Inherits:
-
Object
- Object
- AASM::StateMachine
- Defined in:
- lib/aasm/state_machine.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#events ⇒ Object
Returns the value of attribute events.
-
#global_callbacks ⇒ Object
Returns the value of attribute global_callbacks.
-
#initial_state ⇒ Object
Returns the value of attribute initial_state.
-
#name ⇒ Object
Returns the value of attribute name.
-
#states ⇒ Object
Returns the value of attribute states.
Class Method Summary collapse
-
.[](klass) ⇒ Object
the following two methods provide the storage of all state machines.
- .[]=(klass, machine) ⇒ Object
Instance Method Summary collapse
- #add_event(name, options, &block) ⇒ Object
- #add_global_callbacks(name, *callbacks, &block) ⇒ Object
- #add_state(state_name, klass, options) ⇒ Object
-
#initialize(name) ⇒ StateMachine
constructor
A new instance of StateMachine.
-
#initialize_copy(orig) ⇒ Object
called internally by Ruby 1.9 after clone().
Constructor Details
#initialize(name) ⇒ StateMachine
Returns a new instance of StateMachine.
15 16 17 18 19 20 21 22 |
# File 'lib/aasm/state_machine.rb', line 15 def initialize(name) @initial_state = nil @states = [] @events = {} @global_callbacks = {} @config = AASM::Configuration.new @name = name end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/aasm/state_machine.rb', line 13 def config @config end |
#events ⇒ Object
Returns the value of attribute events.
13 14 15 |
# File 'lib/aasm/state_machine.rb', line 13 def events @events end |
#global_callbacks ⇒ Object
Returns the value of attribute global_callbacks.
13 14 15 |
# File 'lib/aasm/state_machine.rb', line 13 def global_callbacks @global_callbacks end |
#initial_state ⇒ Object
Returns the value of attribute initial_state.
13 14 15 |
# File 'lib/aasm/state_machine.rb', line 13 def initial_state @initial_state end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/aasm/state_machine.rb', line 13 def name @name end |
#states ⇒ Object
Returns the value of attribute states.
13 14 15 |
# File 'lib/aasm/state_machine.rb', line 13 def states @states end |
Class Method Details
.[](klass) ⇒ Object
the following two methods provide the storage of all state machines
5 6 7 |
# File 'lib/aasm/state_machine.rb', line 5 def self.[](klass) (@machines ||= {})[klass.to_s] end |
.[]=(klass, machine) ⇒ Object
9 10 11 |
# File 'lib/aasm/state_machine.rb', line 9 def self.[]=(klass, machine) (@machines ||= {})[klass.to_s] = machine end |
Instance Method Details
#add_event(name, options, &block) ⇒ Object
40 41 42 |
# File 'lib/aasm/state_machine.rb', line 40 def add_event(name, , &block) @events[name] = AASM::Core::Event.new(name, self, , &block) end |
#add_global_callbacks(name, *callbacks, &block) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/aasm/state_machine.rb', line 44 def add_global_callbacks(name, *callbacks, &block) @global_callbacks[name] ||= [] callbacks.each do |callback| @global_callbacks[name] << callback end @global_callbacks[name] << block if block end |
#add_state(state_name, klass, options) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/aasm/state_machine.rb', line 31 def add_state(state_name, klass, ) set_initial_state(state_name, ) # 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, ) end |
#initialize_copy(orig) ⇒ Object
called internally by Ruby 1.9 after clone()
25 26 27 28 29 |
# File 'lib/aasm/state_machine.rb', line 25 def initialize_copy(orig) super @states = @states.dup @events = @events.dup end |