Ruby-on-rails Rails 3 中 Gemfile 中的组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3645968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Groups in a Gemfile in Rails 3?
提问by never_had_a_name
In my Gemfile in Rails I have these groups:
在 Rails 中的 Gemfile 中,我有这些组:
group :development, :test do
gem "capybara"
gem "database_cleaner"
gem "spork"
gem "launchy"
end
group :bdd do
gem "cucumber-rails"
gem "rspec-rails"
end
What does this mean?
这是什么意思?
回答by David Lyod
From http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/:
来自http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/:
Specifying groups allows you to do two things. First, you can install the gems in your Gemfile, minus specific groups. For instance, Rails puts mysql and pg in a database group so that if you're just working on ActionPack, you can bundle install --without db and run the ActionPack tests without having to worry about getting the gems installed.
Second, you can list specific groups to autorequire using Bundler.require. By default, Bundler.require requires all the gems in the default group (which is all the gems that have no explicit group). You can also say Bundler.require(:default, :another_group) to require specific groups.
指定组允许您做两件事。首先,您可以在 Gemfile 中安装 gem,减去特定组。例如,Rails 将 mysql 和 pg 放在一个数据库组中,这样如果你只是在 ActionPack 上工作,你可以 bundle install --without db 并运行 ActionPack 测试,而不必担心安装 gems。
其次,您可以使用 Bundler.require 列出要自动要求的特定组。默认情况下,Bundler.require 需要默认组中的所有 gem(即所有没有明确组的 gem)。你也可以说 Bundler.require(:default, :another_group) 来要求特定的组。
回答by Ben Flynn
Grouping your dependencies allows you to perform operations on the entire group.See: http://gembundler.com/v1.3/groups.html
对依赖项进行分组允许您对整个组执行操作。见:http: //gembundler.com/v1.3/groups.html
回答by Josh
Answer updated to Bundler 1.3 -> http://gembundler.com/v1.3/groups.html
答案更新到 Bundler 1.3 -> http://gembundler.com/v1.3/groups.html

