auto installing a gem

Discussion in 'Ruby' started by bpettichord@gmail.com, Aug 16, 2006.

  1. Guest

    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
     
    , Aug 16, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. linkswanted
    Replies:
    1
    Views:
    993
  2. Austin 7873
    Replies:
    5
    Views:
    216
    Eric Hodel
    Jan 27, 2007
  3. Pat Maddox
    Replies:
    2
    Views:
    130
    David Masover
    Aug 3, 2008
  4. Nasir Khan
    Replies:
    0
    Views:
    117
    Nasir Khan
    Jun 8, 2009
  5. Adinda P.
    Replies:
    0
    Views:
    218
    Adinda P.
    Nov 6, 2010
Loading...

Share This Page