Tuesday, September 15, 2009

A better mategem

I've just built a nicer "mategem" command, which will open up a rubygem's root directory in textmate. It allows you to simply open the latest gem version using the same reference you use in your project to activate the gem.

You know how you can activate a gem by running the gem command (e.g. "gem 'rails'"), or also by simply requiring a library file that is provided by that gem in the root of its library (like "require 'action_controller'" will activate the 'actionpack' gem)? Well, you can use the same two ways to reference a gem when you run mategem:

  • "mategem rails" will open rails
  • "mategem initializer" will also open rails
  • "mategem action_controller" will open the actionpack gem
  • "mategem sinatra" will of course open the sinatra gem
Here is the code for the command. Basically how it works: Tries to reference it as a gem name, if that works, take the last-added load path as the gem path. If that doesn't work, try to have `gem which` find it as a gem-provided library. If that works, we have the path given to us. Parse out where the gem's root folder is, and open it up in mate!


To install, create this file, make it executable, and put it somewhere in your PATH. I would highly advise creating a ~/.bin folder and putting that in your PATH.

0 comments: