我们的团队有几个人,其中任意数量的人都可能致力于任意宝石的组合。目前,我们的 Gemfile 有这样的内容:
gem 'awesome-gem', :git => '[email protected]:somebody/awesome-gem.git'
# gem 'awesome-gem', :path => '/Users/developer-A/workspace/awesome-gem'
# gem 'rad-gem', :git => '[email protected]:somebody/rad-gem.git', :branch => 'release'
gem 'rad-gem', :path => '/some/path/specific-to/developer-B/rad-gem'
因此,开发人员 A 正在本地开发 Awesome-gem,当他们完成时,他们只是将其 :path 替换为 gem 的 :git 位置,并将两者都提交给版本控制。 Developer-B 和 C 对 rad-gem 做同样的事情,每个人在本地修改的 Gemfile 中都有不同的 :path,如果每个 Gemfile 都有真正的更改,他们必须撤消本地 :path 设置、提交、撤消以指向回到他们本地版本的 rad-gem 等。
这既痛苦又丑陋,所以我试图想出一个更好的解决方案,但我能想出的最好的解决方案是这样的:
if ENV['RADGEM_PATH']
gem 'rad-gem', :path => ENV['RADGEM_PATH']
else
gem 'rad-gem', :git => '[email protected]:somebody/rad-gem.git', :branch => 'release'
end
这允许开发人员 B 和 C设定自己的rad-gem 路径,同时消除了上面提到的大部分痛苦。然而,它仍然很难看,我想知道是否有更好的方法来做到这一点,可能使用组?
Our group has several people, any number of which may be working on any combination of gems. Currently, our Gemfile has stuff like this:
gem 'awesome-gem', :git => '[email protected]:somebody/awesome-gem.git'
# gem 'awesome-gem', :path => '/Users/developer-A/workspace/awesome-gem'
# gem 'rad-gem', :git => '[email protected]:somebody/rad-gem.git', :branch => 'release'
gem 'rad-gem', :path => '/some/path/specific-to/developer-B/rad-gem'
So developer-A was working on awesome-gem locally, and when they finished up, they just replaced their :path the gem's :git location and committed both to version control. developer-B and C do the same thing for rad-gem, each has a different :path in their locally modified Gemfile and if the Gemfile every has real changes, they have to undo their local :path setup, commit, undo to point back to their local version of rad-gem, etc.
This is both a pain and ugly, so I tried to come up with a better solution but the best I could come up with is something like this:
if ENV['RADGEM_PATH']
gem 'rad-gem', :path => ENV['RADGEM_PATH']
else
gem 'rad-gem', :git => '[email protected]:somebody/rad-gem.git', :branch => 'release'
end
This allows developer-B and C to set their own rad-gem path while removing much of the pain mentioned above. however, it is still ugly and I'm wondering if there is a better way to do this, possibly using groups?
发布评论
评论(2)
更新(当前)
最近对 bunder 的更新现在提供了 本地 git 存储库。这是目前解决这个问题的方法。谢谢 sekrett
更新(已过时)
如果您有 Bundler >= 1.2,现在有一个 更好的方法。例如,
原始答案(已过时)
我在 rspec 核心团队的一位朋友向我展示了他们在 rspec-core Gemfile 中使用的方法,所以我想我会使用它。
Update (current)
A recent update to bunder now provides local git repos. This is the current way of solving this problem. Thank you sekrett
Update (outdated)
If you have Bundler >= 1.2, there is now a better way to do this. For example,
original answer (outdated)
A friend of mine on the rspec core team showed me the approach they used in the rspec-core Gemfile, so I guess I'll use that.
难道您不能拥有一个动态 Gemfile,在开发过程中使用隐藏文件 (.my_local_gems) 作为该用户计算机上 gem 的位置吗?或者您甚至可以使用一些环境变量作为 GEMS_DEVEL_HOME 之类的变量?
无论哪种方式,它都会迫使每个人保持所有本地 gem 为最新,并且在生产或暂存中,正常的 Gemfile 将生效。
请记住,Gemfile 只是 ruby,因此您可以在其中包含各种代码,而不仅仅是特定于捆绑程序的习惯用法。
Couldn't you also have a dynamic Gemfile that in development uses a hidden file (.my_local_gems) for the location of gems on that user's machine? Or you could even use some environment variable for a variable like GEMS_DEVEL_HOME?
Either way, it would force everyone to keep all of their local gems up to date and in production or staging, the normal Gemfile would take effect.
Remember, the Gemfile is just ruby so you can include all kinds of code in there, not just bundler-specific idioms.