Skip to content

Instantly share code, notes, and snippets.

@afeld
Created June 13, 2013 19:51
Show Gist options
  • Save afeld/5776771 to your computer and use it in GitHub Desktop.
Save afeld/5776771 to your computer and use it in GitHub Desktop.
add version approximation strings to Gemfile
out = ''
File.readlines('./Gemfile').each do |line|
match = line.match(/^(.*)gem '([^']+)'(, require: false)?$/)
if match
name = match[2]
version = Gem.loaded_specs[name].version
ver_str = version.to_s
if ver_str.start_with?('0.')
ver_str = ver_str.sub(/\.\d+$/, '.x')
spec = "~> #{ver_str}"
else
spec = version.approximate_recommendation
end
out << "#{match[1]}gem '#{name}', '#{spec}'#{match[3]}\n"
else
out << line
end
end; 0
File.open('./Gemfile', 'w') {|f| f.write(out) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment