Is it possible to get all events from a model class? I want to filter a list by events.
There was a similar question on mailinglist about all transitions.
I am using https://github.com/pluginaweek/state_machine
Is it possible to get all events from a model class? I want to filter a list by events.
There was a similar question on mailinglist about all transitions.
I am using https://github.com/pluginaweek/state_machine
Right on the github page you link to it shows the API methods for:
vehicle.state_events # shows all the events possible from the current state
and
vehicle.state_paths.events # shows all the events for an object
The accepted answer for some reason takes a few seconds for me to compute. I guess this happens if you have a lot of states.
What works for me is:
Invoice.state_machines[:state].events.map(&:name)
In my case the class name is invoice
and the state_machine is named state
.
edit 2014: this list states, not events
This is how I did it, to only list the keys
def self.membership_states
self.state_machines[:membership_status].states.map(&:name)
end
$ User.membership_states
> [:applied, ...