Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a utility for converting RVM default.gems files to Bundler Gemfiles?

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?

like image 609
pjmorse Avatar asked Mar 22 '11 18:03

pjmorse


2 Answers

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
like image 127
Moiz Raja Avatar answered Sep 30 '22 14:09

Moiz Raja


There is a command in rvm for that:

rvm gemset export Gemfile

It will generate Gemfile with all the gems in gemset.

like image 44
mpapis Avatar answered Sep 30 '22 13:09

mpapis