daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest May 17th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @gems_installed_list = `sudo gem list`
  2.  
  3. begin
  4.   @gems_to_install_list = File.open(ARGV.first)
  5. rescue
  6.   puts "usage: ruby sync_gems.rb your_file_with_gems_list"
  7.   exit 1
  8. end
  9.  
  10. def gem_versions(gem_string)
  11.   if(releases = gem_string.match(/\((.*)\)/)[1])
  12.     releases.split(",").each {|r| r.strip!}
  13.   end
  14. end
  15.  
  16. def gem_name(gem_string)
  17.   gem_string.match(/(.*)\s\(/)[1]
  18. end
  19.  
  20. def gem_exist?(name, version)
  21.   @gems_installed_list.each do |gem_string|
  22.     return true if gem_name(gem_string) == name && gem_versions(gem_string).include?(version)
  23.   end
  24.   false
  25. end
  26.  
  27. # begin
  28.  
  29. @gems_to_install_list.each do |gem_string|
  30.   gem_versions(gem_string).each do |version|
  31.     name = gem_name(gem_string)
  32.     if !gem_exist?(name, version)
  33.       puts "Installing: #{name} version #{version}"
  34.       puts `sudo gem install #{name} -v=#{version} --no-rdoc --no-ri`
  35.     else
  36.       puts "skipping #{name} version #{version}, because it is already installed"
  37.     end
  38.   end
  39. end
RAW Paste Data
Top