@xcombinator
- I realize there are a million already, but I created another git cheatsheet: http://bit.ly/bfAKlZ 2010/09/01
-
Recent Posts
Recent Comments
- ActiveRecord from_json and from_xml (5)
- Terence: Dude, you are the bomb. Thanks for your fix. Helped us out heaps.
- djb daemontools with Ubuntu’s upstart (2)
- sorcess: such config may lead to data loss… consider above configuration with this little change start on...
- Mac OS X color showing ESC[whatever for git-diff colors (and more) (15)
- automate installing tripwire using expect (1)
- Trey Henefield: I came across this as useful. But I found an even easier solution. There is an option that disables...
- ActiveRecord from_json and from_xml (5)
Categories
- bookmarks (2)
- cascading (2)
- code (2)
- crawling (1)
- deployment (6)
- ec2 (3)
- erlang (2)
- gems (3)
- git (7)
- hadoop (3)
- java (1)
- merb (1)
- music (1)
- osx (2)
- poolparty (3)
- processing (1)
- programming (48)
- rails (11)
- ruby (21)
- scalability (5)
- shell (8)
- sysadmin (16)
- tips (13)
- Uncategorized (3)
- useless (1)
Archives
Pages
Blogroll

visualize state_machine’s with graphviz
The guys at Plugin-a-week have written a nice ActiveRecord state machine gem called state_machine.
One of the great things about state machines is that they often can be visualized. To that end I’ve written a small utility that will load a class that uses state_machine and produce dot output which you can use with graphviz.
This gem is currently used by the spree shopping cart. Let’s look at an example of how this can be used to visualize the Order object in this project:
Save the gist below to visualize.rb and chmod +x visualize.rb. The arguments are 1) the path to RAILS_ROOT of the project using state_machine and 2) the class you want to visualize. Try visualize.rb --help to see all the options.
ruby visualize.rb . Order | dot -Tsvg -Grankdir=LR > graph.svg
Gives us the following image:
Download the raw code (Requires ‘trollop’ gem).