Module: ScottBarron::Acts::StateMachine::InstanceMethods
- Defined in:
- lib/acts_as_state_machine.rb
Instance Method Summary collapse
-
#current_state ⇒ Object
Returns the current state the object is in, as a Ruby symbol.
-
#next_state_for_event(event) ⇒ Object
Returns what the next state for a given event would be, as a Ruby symbol.
- #next_states_for_event(event) ⇒ Object
- #run_initial_state_actions ⇒ Object
-
#set_initial_state ⇒ Object
:nodoc:.
Instance Method Details
#current_state ⇒ Object
Returns the current state the object is in, as a Ruby symbol.
150 151 152 |
# File 'lib/acts_as_state_machine.rb', line 150 def current_state self.send(self.class.state_column).to_sym end |
#next_state_for_event(event) ⇒ Object
Returns what the next state for a given event would be, as a Ruby symbol.
155 156 157 158 |
# File 'lib/acts_as_state_machine.rb', line 155 def next_state_for_event(event) ns = next_states_for_event(event) ns.empty? ? nil : ns.first.to.to_sym end |
#next_states_for_event(event) ⇒ Object
160 161 162 163 164 |
# File 'lib/acts_as_state_machine.rb', line 160 def next_states_for_event(event) self.class.read_inheritable_attribute(:transition_table)[event.to_sym].select do |s| s.from == current_state.to_s end end |
#run_initial_state_actions ⇒ Object
143 144 145 146 147 |
# File 'lib/acts_as_state_machine.rb', line 143 def run_initial_state_actions initial = self.class.read_inheritable_attribute(:states)[self.class.initial_state.to_s] initial.entering(self) initial.entered(self) end |
#set_initial_state ⇒ Object
:nodoc:
139 140 141 |
# File 'lib/acts_as_state_machine.rb', line 139 def set_initial_state #:nodoc: write_attribute self.class.state_column, self.class.initial_state.to_s end |