ryanza/stateflow — Issue #25: Method to determine if an event is allowed
Author: cgriego
Created: 2011-10-14 13:02:46+00:00
State: open

To support user input validation logic I'm writing, I need the ability to ask a model if it will allow an event to transition. If the event were name "close" then something like "can_close?". Without a method, I've had to reach deep into the internals of stateflow from my model.

def can_close?
self.class.machine.events[:close].send(:transitions).select do |transition|
transition.from.include? current_state.try(:name)
end.first.try(:can_transition?, self)
end