0

我正在使用 bundler 将内部 git 存储库中的 gem 部署到我的 rails 应用程序中。我想为不同的组设置不同的分支名称,但是,这个:

group :production, :release_candidate, :staging, :demo do
  gem "my_inhouse_gem", '0.0.1', git: 'git@github.com:my_gem.git', branch: 'master'
end

group :development, :develop do
   gem "my_inhouse_gem", '0.0.1', git: 'git@github.com:my_gem.git', branch: 'develop'
end

失败了

You cannot specify the same gem twice coming from different sources.
You specified that mygem (= 0.0.1) should come from      
git@github.com:my_gem.git (at develop) and
git@github.com:my_gem.git (at master)

而以下:

group :production, :release_candidate, :staging, :demo do
  my_gem = 'master'
end

group :development, :develop do
  my_gem = "develop"
end

gem "my_inhouse_gem", '0.0.1', git: 'git@github.com:my_gem.git', branch: my_gem

只需使用最后打印的组。

在阅读并找到这篇文章后:http: //yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/,我意识到这是因为捆绑器仍然会执行内容每个组,然后只需安装匹配的组。

如何根据 Gemfile 中的环境配置获得动态分支名称?

4

2 回答 2

2

Bundler 并非旨在以您想要的方式处理这种情况。它旨在提供一组一致的宝石。组可以控制哪些 gem 安装在什么环境中,但不能切换 gem 的版本。

可能有更好的方法来完成你想要的。如果您需要针对 gem 的实验版本进行开发,最好在项目的一个分支中进行。

另见:https ://github.com/bundler/bundler/issues/751#issuecomment-22113199

于 2013-08-09T06:26:42.013 回答
0

这就是我解决这个问题的方法:

在我的 Gemfile 顶部:

     rails = ENV['RAILS_ENV'] || 'default'

接着:

if rails.match /develop/i or rails.match /ci/ or rails.match /test/ or rails.match /default/i
  # if you wish to test locally against your branch
  #in_house_version = 'your_branch'
  in_house_version = 'develop'
else
  in_house_version = 'master'
end
于 2013-08-09T18:08:13.833 回答