2012-10-09 71 views
4

所以我知道,在一个Gemfile中,我可以做这样的事情:的Gemfile - 从开发中分离生产的宝石宝石

group :development, :test do 
    gem 'gem1' 
    gem 'gem2' 
end 

我所希望做到的是这样的:

group :production do 
    gem 'gem1' 
    gem 'gem2' 
end 

group :development, :test do 
    gem 'gem1', :path => '/Documents/Code/gem1/' 
    gem 'gem2', :path => '/Documents/Code/gem2/' 
end 

所以我们的应用程序使用了我们也在本地开发的2个宝石。为了在我们的本地机器上开发时间更长,我们希望能够将我们的开发环境指向本地的gem副本 - 通过这种方式,它可以在不需要重新启动rails服务器的情况下完成所有更改。否则,我们将不得不重新构建宝石,重新安装宝石,并在宝石的每次开发变化中重新开始导轨。

但是,这样做给了我以下错误:

You cannot specify the same gem twice coming from different sources. You specified that gem1 (>= 0) should come from an unspecfied source and source at /Documents/Code/gem1 

我已经试过甚至运行像bundle install --without production,我也得到了同样的错误。

有谁知道是否有可能做我想做的事情?

谢谢!

回答

5

我认为有一个支持的方式来做到这一点,一些黑客来解决它。

支持方式:

使用bundle configlocal选项如下所述:http://bundler.io/v1.3/man/bundle-config.1.html

哈克的方式:

使用ENV VAR和在生产中使用之前执行捆绑:http://www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/

有是github上关于这个问题的一个功能请求,其中有几个相关的问题和大量的评论:https://github.com/carlhuda/bundler/issues/396

+0

上述链接到'束config'文档已经移动到:http://bundler.io/v1.3/man/bundle- config.1.html –

+0

@AdamFlorin thx,更新了答案 – phoet

5

github问题phoet挂接已解决,并且与支持的方式一致。

我在文档中搜索,您需要设置配置变量并更新您的gemfile以引用分支。

例如在命令行

gem <gem_name>, git: <git_url>, branch: <branch> 

编辑您的Gemfile

bundle config local.<gem_name> <local_path_to_gem> 
0

我通过创建一个新的Gemfile这是除了目标宝石的来源等同于原来的解决了这个。然后,在配置/的boot.rb,我使用:

require 'rails' if Rails.env.development? ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../DevGemfile', __FILE__) else ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../ProdGemfile', __FILE__) end