rubydata-visualizationfsmaasmacts-as-state-machine

Tool to generate state transition diagram for acts_as_state_machine


The ruby gem acts_as_state_machine can be super helpful for modeling object lifecycles within a flexible finite state machine framework. But I often find myself wanting a visual representation of the state transitions.

Is there a tool to generate an FSM diagram (state diagram flowchart, state/event table, UML, etc.) from an existing ruby class that acts_as_state_machine?


Solution

  • The state_machine gem (not to be confused with acts_as_state_machine) has this functionality.

    For example, from the docs:

    $ rake state_machine:draw FILE=vehicle.rb CLASS=Vehicle
    

    state_machine is no longer maintained. Its fork state_machines has extracted diagram functionality into a separate gem state_machines-graphviz. Installing that gem, and then run the renamed rake task:

    $ rake state_machines:draw FILE=vehicle.rb CLASS=Vehicle