Friday, 27 April 2012

import a gem list

If your project doesn't use Gemfile, paste the wanted gemlist in the GEM_LIST string, run this script and that's it. I know, it could be improved, but that's it by now. NOTE: only the first version of the gem is installed, which is the highest.

#!/usr/bin/ruby

gem_list = <<GEM_LIST
actionmailer (2.3.8)
actionpack (2.3.8)
activerecord (2.3.8)
activeresource (2.3.8)
activesupport (2.3.8)
aws-s3 (0.6.3)
barista (1.3.0)
bistro_car (0.2.2)
soap4r (1.5.8)
therubyracer (0.10.2)
will_paginate (2.3.16)
xml-simple (1.1.2)
GEM_LIST

gem_list.split("\n").each do |line|
  gem      = line.match(/^.+? /).to_s # with a space at the end
  versions = line.match(/\(.+\)/)     # surrounded by parenthesis
  highest_version = line.match(/([\d\.]+)/).to_s
  puts `gem install #{gem} -v #{highest_version}`
end

No comments:

Post a Comment