Gem Optional source for `bundle install`

yorzi · September 08, 2013 · Last by Saito replied at September 08, 2013 · 2964 hits

有没有办法让 development 环境使用一个 Gem source, 然后 production 使用另外一个 source?比方类似下面的逻辑:

# Gemfile

if Rails.env.development?
  source 'http://ruby.taobao.org'
else
  source 'http://rubygems.org'
end

gem 'some-gem'

感觉可以啊,有试过吗?

#1 楼 @Rei 不行,Gemfile 不认识 Rails 关键字:

# error log

Gemfile:1:in `eval_gemfile': uninitialized constant Bundler::Dsl::Rails (NameError)
require "rails"
if ::Rails.env.development?
  source 'http://ruby.taobao.org'
else
  source 'http://rubygems.org'
end

但是还是用 ENV 比较好

You need to Sign in before reply, if you don't have an account, please Sign up first.