I've been using acts_as_state_machine and there seems to be at least two convenience methods missing that I find quite useful:
- next_state - what state will we be transitioning to
- next_states - list of states that we still need to transition to
# Monkey patch acts_as_state_machine to allow us to see what the next states areThanks to Lourens Naude's' post on acts_as_state_machine for providing me with some ideas and to Scott Barron for the great acts_as_state_machine plugin.
# for the current state
module ScottBarron
module Acts
module StateMachine
module InstanceMethods
def next_state(state=nil)
state ||= current_state()
self.class.read_inheritable_attribute(:transition_table).each_value do |event|
event.each do |transition|
return transition.to if transition.from == state
end
end
nil
end
def next_states(state=nil)
state ||= current_state()
states = []
while state = next_state(state)
states << state
end
states
end
end
end
end
end