[Mongrel] mongrel cluster and local gems loading problem

Rui Lopes rgl at ruilopes.com
Thu Feb 8 09:53:44 EST 2007


I'm trying to augment the GEM_PATH to load gems from ~/.gem/ using this
at the begging of the rails application config/environment.rb file:

  ENV['GEM_PATH'] = File.expand_path('~/.gem')

This works fine from within script/console:

  $ script/console
>> require 'pdf/writer'
=> true

But when I try to run:

  mongrel_rails cluster::start

It fails to load the local gem.

I started to dig into the code, and realized that rubygems is
initialized by mongrel_rails before it loads the environment.rb file,
which results in GEM_PATH env. variable being "ignored" (because rubygem
Gem.path method caches the path on the first use, which is done by
mongrel_rails).  To make this work, I had come to this hack:

  ENV['GEM_PATH'] = File.expand_path('~/.gem')
  require 'rubygems'; Gem.clear_paths;
Gem.instance_variable_set(:@searcher, nil)

Which clears the internal cache used by rubygems, and forces it to
re-read the GEM_PATH env. variable.

But I don't fell comfortable using it... is there a better way to do
this?  Like, setting the GEM_PATH from the mongrel cluster config file?

Best regards,
Rui Lopes

PS: require 'rubygems' is needed just in case we run script/console from

More information about the Mongrel-users mailing list