LoginSignup
0
0

More than 3 years have passed since last update.

Bundlerのグループのメモ

Last updated at Posted at 2020-04-28

メモ

  • 環境
    • Ruby 2.7
    • Bundler 2.1.4
  • 以下のようにGemfileを用意する
    • rspecg1 グループ
    • rubocopg1g2 グループ
    • prydefault グループ
      • 何も記載しない場合は default というグループに入る
Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "pry"

group :g1 do
  gem "rspec"
end

group :g1, :g2 do
  gem "rubocop"
end

特定の1つのグループを除外する

まず、 g1 グループを除外する設定を入れて、インストールしてみる
※ bundle install 時の --withoutオプションと --path オプションは非推奨となっていたため、 bundle config で指定する

% bundle config set path 'vendor/bundle'
% bundle config set without 'g1'
% bundle

そうすると rspec はインストールされない。それ以外はインストールされる。 rubocop も g2 に所属しているのでインストールされる。
ちなみにGemfile.lockにも rspec もバージョン付きで記載されるが実際にはインストールされない。


このときのGemfile.lock
GEM
  remote: https://rubygems.org/
  specs:
    ast (2.4.0)
    coderay (1.1.2)
    diff-lcs (1.3)
    jaro_winkler (1.5.4)
    method_source (1.0.0)
    parallel (1.19.1)
    parser (2.7.1.1)
      ast (~> 2.4.0)
    pry (0.13.1)
      coderay (~> 1.1)
      method_source (~> 1.0)
    rainbow (3.0.0)
    rexml (3.2.4)
    rspec (3.9.0)
      rspec-core (~> 3.9.0)
      rspec-expectations (~> 3.9.0)
      rspec-mocks (~> 3.9.0)
    rspec-core (3.9.1)
      rspec-support (~> 3.9.1)
    rspec-expectations (3.9.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-mocks (3.9.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.9.0)
    rspec-support (3.9.2)
    rubocop (0.82.0)
      jaro_winkler (~> 1.5.1)
      parallel (~> 1.10)
      parser (>= 2.7.0.1)
      rainbow (>= 2.2.2, < 4.0)
      rexml
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 1.4.0, < 2.0)
    ruby-progressbar (1.10.1)
    unicode-display_width (1.7.0)

PLATFORMS
  ruby

DEPENDENCIES
  pry
  rspec
  rubocop

BUNDLED WITH
   2.1.4

default グループも外す

次は g1default を外してみる
上述のコマンドで設定。
設定確認は以下コマンドで。

% bundle config
without
Set for the current user (/home/xxx/.bundle/config): [:g1, :default]

そうすると、 pryrspec は除外される。

参考

Bundler: bundle install https://bundler.io/man/bundle-install.1.html

Bundler: How to manage groups of gems https://bundler.io/v2.0/guides/groups.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0