If I'm setting up a project to use Bundler, and I already have an RVM gemset for the project, is there an easy way to export the gemset list to Gemfile
(or, for that matter, convert the default.gems
file to a Gemfile
format)? Or are we all just find-and-replacing?
I wanted to generate a Gemfile for an old rails project and I wrote this little script to help me.
#!/usr/bin/env ruby
#Save in file to_gemfile.rb
gem_file = File.open("Gemfile", "w")
gem_file.write("source :rubygems\n")
STDIN.readlines.each do |line|
line = line.chomp
line =~ /(.*)\s\((.*)\)/
gem_name = $1
versions = $2.split(",")
gem_file.write("gem \"#{gem_name}\", \"#{versions.first}\"\n")
end
gem_file.close
Use it like so
$ gem list | ./to_gemfile.rb
There is a command in rvm for that:
rvm gemset export Gemfile
It will generate Gemfile
with all the gems in gemset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With