Created
June 7, 2015 17:01
-
-
Save patbenatar/34551eb94b0aa92d7e12 to your computer and use it in GitHub Desktop.
Write lock versions back to Gemfile
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
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