state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

Find the required states for an event without an instance #72

Closed Papipo closed 5 years ago

Papipo commented 5 years ago

Hi!

How can I find which states can an event transition from without an instance of the underlying model?

I have this code working that uses the machine states, their branches and their state_requirements values, but it seems too involved and coupled to the library.

Thanks.

seuros commented 5 years ago

You will need the instance as a state machine can perform differently dependent on the instance linked to it .

Papipo commented 5 years ago

Even state_machine needs something like this: https://github.com/state-machines/state_machines/blob/master/lib/state_machines/event.rb#L194.

But we can close the issue anyway, I ended up doing something similar to the code above.

Thanks!