在Gemfile的组中指定类似的配置

时间:2015-02-10 12:11:36

标签: ruby-on-rails ruby git bundler

我们有一个rails应用程序,我们将应用程序拆分为引擎。现在我们有很多引擎,所有它们都要指向开发或掌握,比如

gem 'a', :git => "https://github.com/abc/a.git", :branch => 'develop'
gem 'b', :git => "https://github.com/abc/b.git", :branch => 'develop'
gem 'c', :git => "https://github.com/abc/c.git", :branch => 'develop'
gem 'd', :git => "https://github.com/abc/d.git", :branch => 'develop'

我想对它们进行分组,并根据组分支指定,如下所示:

group :development, :branch => 'develop' do
    gem 'a', :git => "https://github.com/abc/a.git"
    gem 'b', :git => "https://github.com/abc/b.git"
    gem 'c', :git => "https://github.com/abc/c.git"
    gem 'd', :git => "https://github.com/abc/d.git"
end

我已经浏览了捆绑文件,但它只指定了如何为每个宝石添加分支。有没有办法在no上做类似的配置。宝石。

2 个答案:

答案 0 :(得分:1)

毕竟,

Gemfile由普通的Ruby组成。你可以这样做:

%w(a b c d).each do |repo|
  gem repo,
    :git => "https://github.com/abc/#{repo}.git",
    :branch => 'develop'
end

答案 1 :(得分:1)

Gemfile有自己的DSL。但没有什么能阻止你在其中使用Ruby:

branch = 'develop'

group :development do
  %(a b c d).each do |lib|
    gem lib, :git => "https://github.com/abc/#{lib}.git", :branch => branch
  end
end