How to reload available rubygems in a long running process

In my Ruby monitoring framework, god, I have the ability to load configuration files into an already running god instance. This allows the user to create new watches without having to restart god. There is a problem, however, if the config file to be loaded requires a gem that was installed *after* god was started. The rubygems system discovers and caches the available gems when it is initially required, ignoring any gems that are installed after that.

I have not been able to find an easy way to have rubygems reload its cache of available gems from a running Ruby program. Does anyone know of a decent way to accomplish this?

···

--
Tom Preston-Werner

* Libraries:
    Chronic (chronic.rubyforge.org)
    God (god.rubyforge.org)
    Fuzed (fuzed.rubyforge.org)
* Site:
    rubyisawesome.com

Gem.clear_paths

···

On Nov 12, 2007, at 10:48 , Tom Werner wrote:

In my Ruby monitoring framework, god, I have the ability to load configuration files into an already running god instance. This allows the user to create new watches without having to restart god. There is a problem, however, if the config file to be loaded requires a gem that was installed *after* god was started. The rubygems system discovers and caches the available gems when it is initially required, ignoring any gems that are installed after that.

I have not been able to find an easy way to have rubygems reload its cache of available gems from a running Ruby program. Does anyone know of a decent way to accomplish this?

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars

This does not appear to work. Here is my test procedure:

# --> cheat gem is NOT installed

require 'rubygems'

begin
  require 'cheat'
rescue LoadError
  # --> so this gets executed
  puts 'fail'
end

gets

# --> program pauses and I install cheat gem
# sudo gem install cheat

Gem.clear_paths

begin
  require 'cheat'
rescue LoadError
  # --> require STILL fails even though Gem:all_load_paths
  # now contains the cheat gem's directory
  puts 'fail'
end

···

On 11/13/07, Eric Hodel <drbrain@segment7.net> wrote:

On Nov 12, 2007, at 10:48 , Tom Werner wrote:
> In my Ruby monitoring framework, god, I have the ability to load
> configuration files into an already running god instance. This
> allows the user to create new watches without having to restart
> god. There is a problem, however, if the config file to be loaded
> requires a gem that was installed *after* god was started. The
> rubygems system discovers and caches the available gems when it is
> initially required, ignoring any gems that are installed after that.
>
> I have not been able to find an easy way to have rubygems reload
> its cache of available gems from a running Ruby program. Does
> anyone know of a decent way to accomplish this?

Gem.clear_paths

--
Tom Preston-Werner

* Libraries:
    Chronic (chronic.rubyforge.org)
    God (god.rubyforge.org)
    Fuzed (fuzed.rubyforge.org)
* Site:
    rubyisawesome.com

Hrm, with RubyGems 0.9.4.7 I ran your script and I get one fail, not two.

···

On Nov 13, 2007, at 23:39 , Tom Werner wrote:

On 11/13/07, Eric Hodel <drbrain@segment7.net> wrote:

On Nov 12, 2007, at 10:48 , Tom Werner wrote:

I have not been able to find an easy way to have rubygems reload
its cache of available gems from a running Ruby program. Does
anyone know of a decent way to accomplish this?

Gem.clear_paths

This does not appear to work. Here is my test procedure:

[...]

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars

Interesting. I've verified that it does indeed work with 0.9.4.7. I was
previously using 0.9.4. Thanks for your help!

···

On 11/13/07, Eric Hodel <drbrain@segment7.net> wrote:

On Nov 13, 2007, at 23:39 , Tom Werner wrote:
> On 11/13/07, Eric Hodel <drbrain@segment7.net> wrote:
>> On Nov 12, 2007, at 10:48 , Tom Werner wrote:
>>> I have not been able to find an easy way to have rubygems reload
>>> its cache of available gems from a running Ruby program. Does
>>> anyone know of a decent way to accomplish this?
>>
>> Gem.clear_paths
>
> This does not appear to work. Here is my test procedure:
>
> [...]

Hrm, with RubyGems 0.9.4.7 I ran your script and I get one fail, not
two.

--
Tom Preston-Werner

* Libraries:
    Chronic (chronic.rubyforge.org)
    God (god.rubyforge.org)
    Fuzed (fuzed.rubyforge.org)
* Site:
    rubyisawesome.com

I think that 0.9.4 was resetting the wrong variable, but that's a dim memory. The beta should become 0.9.5 next week.

···

On Nov 14, 2007, at 24:04 , Tom Werner wrote:

On 11/13/07, Eric Hodel <drbrain@segment7.net> wrote:

Hrm, with RubyGems 0.9.4.7 I ran your script and I get one fail, not
two.

Interesting. I've verified that it does indeed work with 0.9.4.7. I was
previously using 0.9.4. Thanks for your help!

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars