仅对选定的宝石进行捆绑部署 [英] Bundle deployment only for selected gems
问题描述
我只想为系统未提供的一组宝石运行 bundle --deployment
。我试过使用 - with = group
,但它开始为 Gemfile
- 带有
选项与您期望的有点不同。首先查看 安装包$ c - 没有
和 - 选项:
- 无=< list>
在安装过程中跳过引用gem到
的空格分隔列表。如果给出的组在
中给予--with的组列表中,它将从
列表中删除。这是一个记住的选项。
- with =< list>
- 引用宝石进行安装的组的列表。如果给出可选组,则安装它。如果一个组是
,因为在给出的--without记住的组列表中,
将从该列表中删除。这是一个记住的选项。
重要的是要注意 - with
是 not 只是的倒数 - 没有
(尽管 - 带组取消取消出一个以前记住的 - 没有
组,反之亦然),它支持完全不同的功能(一个的组, code>可选=> true
参数。
重要的是, - with
实现不会不包括来自默认群组或未由指定的任何其他群组 - >
。
因此,您有两种选择将您的安装限制为一组宝石:
- 使用
的白名单 - with通过将所有组标记为可选组(使用:optional => true
参数)并传递您希望安装的组,将至 -
,将所有其他可选组排除在外。 使用的黑名单 -
将所有不希望安装的群组传递给 - 不带
。
不幸的是,这两个选项都无法防止安装默认组中的宝石(没有明确指定给组的宝石),所以您必须将您想要排除的所有宝石放置在某个组中。 / p>
该foll由于Gemfile的例子应该有助于澄清:
gemrack#总是安装;不可能排除
group:group,:optional => true do
gemthin#默认情况下未安装;使用--with = group
end
group:another_group,:optional => true do
gemwirble#默认不安装;使用--with = another_group
结束
安装 - group:third_group do
gemactivesupport,2.3.5#默认安装;排除使用--without = third_group
结束
I would like to run bundle --deployment
only for one group of gems that are not provided by the system. I've tried using --with=group
but it started doing for all gems in the Gemfile
解决方案 Bundler's --with
option works a bit different than what you're expecting. Let's first look at the bundle install
man page for --without
and --with
options:
--without=<list>
A space-separated list of groups referencing gems to
skip during installation. If a group is given that is in the
remembered list of groups given to --with, it is removed from that
list. This is a remembered option.
--with=<list>
A space-separated list of groups referencing gems to install. If an optional group is given it is installed. If a group is
given that is in the remembered list of groups given to --without, it
is removed from that list. This is a remembered option.
It is important to note that --with
is not just the inverse of --without
(although a --with
group does cancel out a previously-remembered --without
group and vice versa), it supports an entirely different feature (one implemented more recently, around mid-2015), the (backwards-compatible) concept of an "optional group", which only applies to groups explicitly marked with the optional => true
parameter.
Importantly, the --with
implementation does not exclude gems from either the default group or any other group not specified by --without
.
So you have two options for restricting your installation to just a single group of gems:
- Whitelist using
--with
by marking all groups as "optional groups" (using :optional => true
parameter) and passing the group(s) you wish to install to --with
, leaving all other optional groups excluded.
- Blacklist using
--without
by passing all groups you do not wish to install to --without
.
Unfortunately, neither option is able to prevent gems in the "default group" (gems not assigned to a group explicitly) from being installed, so you must place all gems you ever want to potentially exclude in some group.
The following Gemfile example should help clarify:
gem "rack" # Always installed; impossible to exclude
group :group, :optional => true do
gem "thin" # Not installed by default; install using --with=group
end
group :another_group, :optional => true do
gem "wirble" # Not installed by default; install using --with=another_group
end
group :third_group do
gem "activesupport", "2.3.5" # Installed by default; exclude using --without=third_group
end
这篇关于仅对选定的宝石进行捆绑部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!