How can Bundler/Gemfile be configured to use different gem sources during development?

江枫思渺然 提交于 2019-11-29 05:59:04
Piotr Sarnacki

There is a new feature that allows to do that, by simply specyfing local.gem_name config option, like:

bundle config local.rack ~/path/to/local/rack

This only works if the gem has a git repo and branch specified in the Gemfile.

See thr Bundler docs for more details: http://bundler.io/v1.3/bundle_config.html

micahbrich

Apparently, you can use regular Ruby in your Gemfile. According to this article you can set an environment variable (or any other variable, I've found), to let you pick which version of a gem you want to use.

## based on an ENV variable
if ENV['RACK_ENV'] == "development"
  gem 'awesome', :path => "~/code/awesome"
else
  gem 'awesome', :path => "vendor/gems/awesome-0.0.1"
end

Maybe that'll work. If you need to vendor your in-progress gem maybe you could make a tiny little script that'll set the ENV, vendor it, and reset the ENV. Eh?

Here is a suggestion which I didn't get to fully work (used for a spree theme and I got problems with some stylesheets from the theme):

group :production do
      gem 'gemname', '~> 0.1.6', :git => 'git://github.com/foouser/gemname.git'
end

group :development do
      gem 'gemnamedev', :path => '~/path/gemname' # use local version
end

Duplicate your gemname.gemspec file and call it gemnamedev.gemspec, and change s.name inside it to "gemnamedev".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!