In state_machine, how do I find which events are v

2019-08-04 19:31发布

问题:

I am using Aaron Pfeifer's state_machine gem in my Rails3 app -- it's nifty.

How do get a list of events are legal in the current state? By this, I do not mean my_model.state_path.events which returns all events transitively traceable from the current state -- I want only those that are available in the current state.

I'm pretty sure I'm simply overlooking something obvious.

回答1:

Aaron himself answered the question on the PluginAWeek:Core group mailing list:

Hi - You can see the list of helper methods that get generated for each state machine in the docs for the #state_machine macro under the heading "Instance Methods": http://rdoc.info/github/pluginaweek/state_machine/master/StateMachine... Here you'll notice a few instance methods which should help you along:

  • state_events - Gets the list of events that can be fired on the current object’s state (uses the unqualified event names)
  • state_transitions - Gets the list of transitions that can be made on the current object’s state
  • state_paths - Gets the list of sequences of transitions that can be run from the current object’s state Hope this helps! Best, Aaron