Skip to content

Instantly share code, notes, and snippets.

@patbenatar
Created June 7, 2015 17:01
Show Gist options
  • Save patbenatar/34551eb94b0aa92d7e12 to your computer and use it in GitHub Desktop.
Save patbenatar/34551eb94b0aa92d7e12 to your computer and use it in GitHub Desktop.
Write lock versions back to Gemfile
gemfile = File.read('Gemfile')
locks = Bundler.locked_gems
specs = locks.specs
# Naively convert to single quotes
gemfile.gsub! '"', "'"
specs.each do |gem|
# Don't try to set versions on git or github sources
# Don't match if version is already set
gemfile.gsub! /^(?!.*, (git:|github:|'))( *gem '#{gem.name}')/, "\\2, '~> #{gem.version}'"
end
File.open 'Gemfile', 'w+' do |file|
file.puts gemfile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment