Wednesday, December 2, 2009

REE playing nice with rake gems:install

Following the advice by Pratik Naik given during his talk at Rails Summit Latin America, I decided to setup Passenger in development mode. While at it why not setup Ruby Enterprise Edition (REE) also? So I did that but rake gems:install (or in my case /opt/ree/bin/rake gems:install would not install the gems in the REE environment.

A bit of source spelunking turned out that Rails doesn't use Rubygems in a very elegant wait to run the rake tasks, mostly forking a new gem process. Even worse, Gem::Dependency simply guesses which gem command to run based on the current platform. I monkey-patched my Rakefile to force it to use REE (it's a project-specific file anyway) and that worked for me. It's not elegant and not portable but it's hard to make a case as to the "right" way of doing it, except for using the loaded Gem class (!!) correctly. If I ever get to doing that I'll submit a patch. For now, you can append this to your Rakefile:


module Rails
class GemDependency < Gem::Dependency
private
def gem_command
'/opt/ree/bin/gem'
# or File.dirname(File.readlink("/proc/#{$$}/exe")) + '/gem'
end
end
end


and simply running sudo /opt/ree/bin/rake gems:install will work as expected.

No comments: