Last active
August 29, 2015 14:03
-
-
Save lcguida/8834b3326d8b16a75154 to your computer and use it in GitHub Desktop.
Downloads all the gems from a Gemfile.lock. Inspired by https://gist.github.com/flavio/1722530
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler' | |
require 'fileutils' | |
TMP_DIR = "/tmp/gems" | |
#If directory exists, delete it and recreates. | |
FileUtils.rm_rf(TMP_DIR) if File.exists?(TMP_DIR) | |
FileUtils.mkdir TMP_DIR | |
#read the Gemfile.lock | |
lockfile = Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock")) | |
#Download gems | |
lockfile.specs.each do |spec| | |
puts "Downloading gem #{spec.name}-#{spec.version}" | |
Dir.chdir TMP_DIR do | |
cmd = "gem fetch #{spec.name} -v #{spec.version}" | |
if !system(cmd) | |
warn "Error while downloading gem #{spec.name}-#{spec.version}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment