Class: AASM::StateMachine
- Inherits:
-
Object
- Object
- AASM::StateMachine
- Defined in:
- lib/aasm/state_machine.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
the following four methods provide the storage of all state machines.
-
#events ⇒ Object
the following four methods provide the storage of all state machines.
-
#global_callbacks ⇒ Object
the following four methods provide the storage of all state machines.
-
#initial_state ⇒ Object
the following four methods provide the storage of all state machines.
-
#name ⇒ Object
the following four methods provide the storage of all state machines.
-
#states ⇒ Object
the following four methods provide the storage of all state machines.
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.
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
#config ⇒ Object
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 |
#events ⇒ Object
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_callbacks ⇒ Object
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_state ⇒ Object
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 |
#name ⇒ Object
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 |
#states ⇒ Object
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, , &block) @events[name] = AASM::Core::Event.new(name, self, , &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, ) 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()
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 |