lunedì 21 aprile 2008

Daily Fight: railroad.

Today I need to get the whole picture of a rails application. I'm an old school man, I want papers with box, arrows and description to understand relationship between things.
Nowadays Rails guys, starts coding and usually doesn't produce any Diagram with all the stuff inside. I know, it's mine limit, I'm not able to read, remember, clarify and think on a rails statement like:

class User

  • has_many :friendship
  • has_many :mails
  • has_and_belongs_to_many : items

It is very readeable and of immediate lecture, but I need box and arrow on papers. The Rails community is very active, and a colleque of mine pointed me an old (two years old) gem that provide graphics. First impression was "bLeah, i like UML, this is not UML" ruby guys are so modern... After some reading I discovered diagrams are in Business Object Notation. Ok it is not so spread, but is a common way to describe concepts; an interesting point is that is embedded in Eiffel.

A quick search for BON with google produce "BonMagazine" or "Bonjovi" .
BON doesn't have the commercial success and consensum of UML.

To generate BON diagram i proceed in installing gem railroad. Installation works without any issue. Fast and easy.

Railroad generate files into the DOT format, so you need a particular graph visualization software to see diagrams "graphwiz".

This software provides a way to render railroad-dot files, into svg/ps/gif at your pleasure.
With this installation:
railroad, graphwiz package I'm able to generate graph for "models".

But I want also controllers.
Generating controllers need gem RMagick.
Gem RMagick need ImageMagic. Wow I need the entire WWW to generate a BON diagram!

I'm quite lucky, on my MacBook I have darwin port, ready to work for me, so:
sudo ./port install ImageMagick

It takes a lot, about 20 mins, to download and compile all the stuff to enable ImageMagic.

After successfully installing ImageMagic I can proceed with RMagic gem.
Before installing I need to set my $PATH with ImageConf.
export PATH=$PATH:/opt/local/bin/

ok, let's install rmagic:
gem install rmagick -- --with-opt-lib=/opt/local/lib/ --with-opt-include=/opt/local/include/ --with-opt-dir=/opt/local/bin/

After sucessfull installation, all went fine, no errors I use the irb to check the version of just installed gem and check if really works.
irb -rubygems -r RMagick
>> puts Magick::Long_version
This is RMagick 2.3.0 ($Date: 2008/03/29 15:23:12 $) Copyright (C) 2008 by Timothy P. Hunter
Built with ImageMagick 6.4.0 04/21/08 Q16
Built for ruby 1.8.6

Ok, all works fine, so test your railroad controllers generation:
railroad $* -l -i -a -C | dot -Tgif > controller.gif
railroad $* -l -i -a -M | dot -Tgif > model.gif

Task accomplished: Railroad generates my BON diagrams.
And now, let's start thinking...