class Guileless::StateMachine
Public Class Methods
before_transition(name, states, options={})
click to toggle source
# File lib/guileless/state_machine.rb, line 10 def before_transition(name, states, options={}) transitions << [name, Array(states), options] end
transitions()
click to toggle source
# File lib/guileless/state_machine.rb, line 6 def transitions @transitions ||= [] end
Public Instance Methods
state()
click to toggle source
# File lib/guileless/state_machine.rb, line 15 def state raise NoStateError unless @state @state end
transition(new_state)
click to toggle source
# File lib/guileless/state_machine.rb, line 20 def transition(new_state) self.class.transitions.each do |callback, callback_states, options| if callback_states.include?(new_state) if !options[:from] || options[:from].include?(state) self.send("#{callback}".to_sym) end end end @state = new_state end