Skip to content

Instantly share code, notes, and snippets.

@lcguida
Last active August 29, 2015 14:03
Show Gist options
  • Save lcguida/8834b3326d8b16a75154 to your computer and use it in GitHub Desktop.
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
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