如何为项目安装多个Gemfiles?

时间:2018-05-25 10:32:34

标签: ruby-on-rails ruby rubygems bundler

在我的团队中,有些人喜欢使用pry-rails宝石而其他人不喜欢它。

有没有办法让一个辅助Gemfile用于开发,我没有将它提交给git并且仍然被bundler读取?

2 个答案:

答案 0 :(得分:5)

你可以运行:

BUNDLE_GEMFILE=/path/to/another/gemfile bundle install 

或者在Gemfile中(将与已提交的Gemfile.lock产生冲突):

gem 'pry-rails' if ENV['WITH_PRY']

并填充 WITH_PRY env变量以启用pry。

避免Gemfile.lock与Rails应用程序冲突的另一个解决方案:

# In Gemfile
group :dev_with_pry do
  gem 'pry-rails'
end

dev_with_pry 添加到 RAILS_GROUPS env变量,这将安装gem但不需要它。

答案 1 :(得分:0)

根据共享的规范,您可以通过拥有两个gemfiles来管理,并根据环境要求它们。

Gemfile

source 'https://rubygems.org'
gemfiles = [ 'Gemfile1', 'Gemfile2' ]
gemfiles.each do |gemfile|
    instance_eval File.read(gemfile)
  end
end

现在你可以拥有两个独立的Gemfile,例如

Gemfile1

source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

gem 'pry'

然后可以在Gemfile2中添加其他宝石

Gemfile 2

source 'https://rubygems.org'

https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
 gem 'sdoc', require: false
end

希望它能帮助!!