auto installing a gem

B

bpettichord

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top