2

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?

pje
  • 21,801
  • 10
  • 54
  • 70

4 Answers4

2

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
lulalala
  • 17,572
  • 15
  • 110
  • 169
pje
  • 21,801
  • 10
  • 54
  • 70
1

A very late response but I'm using AASM and I've got the same problem. Forget about the state_machine gem. It hasn't been updated for 4 years now and doesn't look like it ever will. The best option I've found for AASM, is to download OpenOffice and use the OpenOffice Draw tool to generate a flow diagram. OpenOffice is free and it's very easy to use.

Obviously it would be far better if this was supported internally by AASM. Unfortunately it isn't.

RamJet
  • 293
  • 1
  • 2
  • 13
1

https://github.com/padde/stateoscope gem works with the AASM gem (previously known as acts_as_state_machine)

David
  • 149
  • 1
  • 4
0

Check aasm-diagram gem, seems newer.

MegaTux
  • 1,591
  • 21
  • 26