[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

auto installing a gem

bpettichord

8/16/2006 6:24:00 PM

I thought it would be clever to require a gem -- and then if it wasn't
found -- to install it automatically. I tried this for both a local gem
file and for a remote install. I wasn't able to get this to work in
either case and am now of the opinion that the Gem library isn't
designed to support this use case.

Here is one version of my code.

workspace_dir = File.join(File.dirname(__FILE__), '..', '..')
package_dir = File.join(File.dirname(__FILE__), '..', 'packages')
watir_dir = File.join(workspace_dir, 'watir')
gem_file = File.join(package_dir, 'watir-'+watir_version+'.gem')
if File.exists?(watir_dir) && use_local_watir
$LOAD_PATH.unshift File.join(workspace_dir, 'watir')
else
require 'rubygems'
begin
require_gem 'watir', '>= ' + watir_version
rescue Gem::LoadError
require 'rubygems/installer'
specs = Gem::Installer.new(gem_file).install
puts "Gem installed: #{specs}"
end

At this point, i'm just sharing what i've learned. If any one has
reached other conclusions, i would be happy to hear about it.

Bret