Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
making a list of gems, installing that list of gems.
#!/usr/local/bin/ruby
def make_gem_list
File.open("gemlist.txt", "w") do |file|
file.write `gem list`.gsub(/\s[(].*[)]/, "")
end
end
def install_gems
File.open("gemlist.txt", "r").each do |gm|
st = gm.strip
`sudo gem install #{gm}` unless `gem list`.include?(st)
puts "installed gem #{gm}"
end
end
def missing_list
current_gems =`gem list`.gsub(/\s[(].*[)]/, "").split("\n")
file_gems = []
File.open("gemlist.txt", "r").each do |gm|
file_gems.push(gm.strip)
end
missing_gems = file_gems - current_gems
if missing_gems.count > 0
missing_gems.each do
|gm| puts "Missing Gem #{gm} in current installation"
end
else
puts "No missing gems"
end
end
puts "Choose to make a list or install gems from a file"
puts "1 = Make a file with a list of gems currently installed"
puts "2 = Install all gems not on both lists."
puts "3 = See what gems are missing between your list and installation"
choice = gets.chomp
if choice == "1"
make_gem_list
elsif choice == "2"
install_gems
elsif choice == "3"
missing_list
else
puts "ERROR: #{choice} is not a valid choice."
end
# By GB Hoyt
#Copyright (c) 2014 GB Hoyt
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment