Skip to content

Instantly share code, notes, and snippets.

@itszero
Created March 19, 2011 05:34
Show Gist options
  • Save itszero/877250 to your computer and use it in GitHub Desktop.
Save itszero/877250 to your computer and use it in GitHub Desktop.
old_gem = "gem"
new_gem = "/opt/ruby-enterprise/bin/gem"
oldgems = `#{old_gem} list`
# oldgems.each block written by spiceee.
# http://snippets.dzone.com/posts/show/6372
oldgems.each do |line|
newgems = `#{new_gem} list`
matches = line.match(/([A-Z].+) \(([0-9\., ]+)\)/i)
if matches
then
gem_name = matches[1]
versions = matches[2]
versions.split(', ').each do |ver|
cmd = "#{new_gem} install #{gem_name} --version #{ver} --no-rdoc --no-ri"
# rubygems-update is "installed" because REE includes RubyGems 1.3.1.
if newgems =~ /#{gem_name} \(.*#{ver}.*\)/i || gem_name =~ /rubygems-update/
then
puts "#{gem_name} #{ver} is already installed. Skipping."
else
puts cmd
system cmd
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment