开发者

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?


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.


run "bundle install" !

it will use the gems which were installed under RVM on the command line (if they are installed already)

check Ryan Bates RailsCast on Bundler: http://railscasts.com/episodes/201-bundler


It looks like the rails_upgrade plugin provides this capability through its rake rails:upgrade:gems task. Its description of this rake task is that it will:

Generate a Gemfile from your config.gem directives

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜