LoginSignup
13
12

More than 5 years have passed since last update.

Gemfileの一部を書き換えたGemfileを定義する方法

Posted at

たとえば Travis CI は CI 固有の Gemfile を指定することでインストールする gem の数を減らしたり、などの方法をとることができる。

ほかにも、たとえば Rails の複数のバージョンでアプリケーションを実行したいときなど、(Bundler の group を使うより) Gemfile をわけるシチュエーションは考えられる。

Gemfile で定義されている依存のマージを行いたい、というときにどうすればよいか。

eval_gemfile

Gemfile を評価する場合、eval_gemfile(gemfile) で評価する。

dependencies

gem メソッドで追加された依存 gem は dependencies というメソッドが記憶している。

dependencies は Gem::Dependency のインスタンスを含む配列である。

やりかた

Gemfile
gem 'rspec'
gem 'simplecov'
gemfiles/travis.Gemfile
eval_gemfile File.expand_path(File.join(File.dirname(__FILE__), '../Gemfile'))

ignored_gems = %w(simplecov)

dependencies.delete_if {|_| ignored_gems.include?(_.name) }
command
bundle install --gemfile gemfiles/travis.Gemfile
13
12
2

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
13
12