Skip to content

Instantly share code, notes, and snippets.

@lime
Created January 1, 2015 18:39
Show Gist options
  • Save lime/b31297a882d432869008 to your computer and use it in GitHub Desktop.
Save lime/b31297a882d432869008 to your computer and use it in GitHub Desktop.
Add current version as a minimum version to gems without version constraints in Gemfile
#!/usr/bin/env ruby
file_name = 'Gemfile'
text = File.read(file_name)
new_contents = text.gsub(/^\s*gem ['"]([\w_\-]+)['"]$/) do
original = Regexp.last_match[0]
gem_name = Regexp.last_match[1]
current_version = Gem.loaded_specs[gem_name].version.to_s
"#{original}, '>= #{current_version}'"
end
File.open(file_name, 'w') do |file|
file.puts new_contents
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment