« Project SOULTRAIN: Not Forgotten | Main | Portability? »

December 02, 2004

Peas, Cyrus and Ruby

Garlic

Alex made peas tonight, adding nothing but garlic. I thought it was awesome, but it shows what a sap I am for garlic.

I Hate Cyrus

Today at work I wrote the following shell script:

function rebuild_email()
{
  while test -d /var/imap.old$x; do
      x=$(($x+1))
  done
  mv /var/imap /var/imap.old$x

  /usr/bin/cyrus/tools/mkimap
  chown -R cyrus:mail /var/imap
  sudo -u cyrus /usr/bin/cyrus/bin/reconstruct -i
}

Can anyone guess what this does? Yes, that’s right, it rebuilds the Cyrus database! Because Cyrus is based on a wonderful library called BerkDB, the motto is “it’s so fast, you won’t even notice that your data isn’t safe!” Cyrus never loses email—because it always keeps a copy of the original delivery prior to being put in the lossy BerkDB, so that you have to run this handy little script every day or so to get your mail back on MacOS X Server. Wow!

Ruby

Though I love Python, Ruby really has its shit together in a couple areas. Firstly, there is a standard Ruby documentation system, RDoc, which can extract useful information from comments in either C extensions or pure Ruby. It produces nice Doxygen looking pages, but I’ve found it to be much more helpful with Ruby because Ruby developers still believe in natural language for explaining things.

Secondly, Ruby has a single built-in testing system, Test::Unit. Python has one too, but this is cool not in-and-of-itself.

Finally, Ruby now has a soon-to-be-standard packaging system, RubyGems. This system will remotely fetch and install libraries, following dependencies, a la CPAN but without the skank. The package (“gem”, as it were) is basically a tar ball with a script that generates a GemSpecification object. You fill in the blanks descriptively, it figures out how to install the gem (or you can use Rake or whatever). Then, after it’s installed, it runs your unit tests to ensure it’s all in working order (like CPAN) plus it generates the documentation from RDoc (like Perl). But wait! There’s more! Every Gem includes a version, so that instead of using your usual require ‘foo’ you can instead put in a requirement for the gem itself, like this: require_gem ‘my_package’, ‘> 1.0’. The require_gem works a lot like Gentoo’s versioning system: Library versions have an X.Y.Z format; when X is incremented, there are backwards incompatible changes, when Y is incremented, features are added, and when Z is incremented, bugs are fixed. This is just a convention, of course, but everyone seems to be following it. There’s also a “pessimistic comparison” operator, which lets you say “I want any version greater than X[.Y[.Z]], so long as X is the same.”

How cool is that? It’s like the best packaging system around. Plus, it comes with GemServer, which gives you a browser to look at the RDoc documentation (because it doesn’t keep the HTML around necessarily if it can generate it on the fly) and see what you have installed. In the future, it’s going to provide for a peer-to-peer gem distribution system. :)

Ruby is just awesome.

Posted by FusionGyro at December 2, 2004 11:48 PM

Trackback Pings

TrackBack URL for this entry:
http://www.clanspum.net/~fusion/blog/admin/mt-tb.cgi/63

Comments

Post a comment




Remember Me?

(you may use HTML tags for style)

Want HTML? Use Textile instead.