pluginaweek / state_machine

Adds support for creating state machines for attributes on any Ruby class
http://www.pluginaweek.org
MIT License
3.74k stars 505 forks source link

How to get list of event eligible events? #362

Open gamesover opened 5 years ago

gamesover commented 5 years ago
event :start do
       transition :parked => :in_motion
    end

    event :stop do
       transition :in_motion => :parked
    end

    state(:in_motion, value: 0)

I want to get the list of eligible states, such as MyClass.state_machine.events[:stop][:from], get result of [0]

rocket-turtle commented 5 years ago

I don't know if that is possible.

MyClass.state_machine.events[:stop].branches.flat_map(&:state_requirements).flat_map { |sr| sr[:from].description }.uniq Something like this could help but there is a Problem mit StateMachines::BlacklistMatchers

agbodike commented 5 years ago

FYI: This gem is abandoned, it has been forked at: https://github.com/state-machines/state_machines