Method: Olib.install

Defined in:
lib/Olib.rb

.install(g, v = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/Olib.rb', line 46

def Olib.install(g, v=nil)
  if !which("gem") then
    echo "Olib could not detect the `gem` executable in your $PATH"
    echo "when you installed Ruby did you forget to click the `modify $PATH` box?"
    raise Exception
  end

  begin
    unless v.nil?
      # make it a true instance of Gem::Version so we can compare
      raise UpdateGemError if Gem.loaded_specs[g].version <  Gem::Version.new(v)
      gem g, v
    end

    Olib.reload g

  ##
  ## rescue missing gem and reload after install
  ##
  rescue LoadError
    echo "installing #{g}..."
    version = "--version '#{v}'" unless v.nil?
    worked = system("gem install #{g} #{version} --no-ri --no-rdoc")
    unless worked then raise "Could not install #{g} gem" end
    Olib.reload g
    echo "... installed #{g}!"

  ##
  ## rescue from too old of a gem version for a Ruby environment
  ##
  rescue UpdateGemError
    echo "updating #{g}@#{Gem.loaded_specs[g].version} => #{v}..."
    version = "--version '#{v}'" unless v.nil?
    worked = system("gem install #{g} #{version} --no-ri --no-rdoc")
    unless worked then raise "Could not install #{g} gem" end
    Olib.reload g
    echo "... updated #{g} to #{v}!"
  end
end