在开发过程中如何配置 Bundler/Gemfile 以使用不同的 gem 源? [英] How can Bundler/Gemfile be configured to use different gem sources during development?

查看:10
本文介绍了在开发过程中如何配置 Bundler/Gemfile 以使用不同的 gem 源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Sinatra 应用程序,它需要我在本地开发的另一个 gem.我在配置 Bundler 以在开发期间使用我的本地 gem 代码但在生产中使用我的供应商 gem 代码时遇到问题.

I have a Sinatra application that requires another gem I'm developing locally. I'm having trouble configuring Bundler to use my local gem code during development but my vendored gem code in production.

理想情况下我可以这样做,但 Bundler 不允许您两次指定同一个 gem:

Ideally I could do something like this, but Bundler doesn't allow you to specify the same gem twice:

# Doesn't work:
group :development do
  gem 'awesome', :path => "~/code/awesome"
end

group :production do
  gem 'awesome', :path => "vendor/gems/awesome-0.0.1"
end

与此同时,我已经求助于手动出售 gem &每次部署时都更新 Gemfile 中的 gem 源,这很麻烦.我的工作流程是这样的:

In the meantime I've resorted to manually vendoring the gem & updating the gem source in the Gemfile every single time I deploy, which is quite a hassle. My workflow is this:

  1. 在开发过程中指向我的本地 gem (gem 'awesome', :path => "~/code/awesome")
  2. 准备好部署后,将 gem 解压到 vendor/gems
  3. 更新 Gemfile 以指向 vendored gem (gem 'awesome', :path => "vendor/gems/awesome-0.0.1")
  4. 运行 bundle install(更新 Gemfile.lock)
  5. 部署代码
  6. 返回第 1 步.
  1. Point to my local gem during development (gem 'awesome', :path => "~/code/awesome")
  2. When ready to deploy, unpack gem into vendor/gems
  3. Update Gemfile to point to vendored gem (gem 'awesome', :path => "vendor/gems/awesome-0.0.1")
  4. Run bundle install (to update Gemfile.lock)
  5. Deploy code
  6. Return to step 1.

真是麻烦!我想做一些更简洁的事情,而不是简单地编写 Rake 任务来自动化我当前的设置.

What a hassle! I'd like to do something cleaner than simply writing Rake tasks to automate my current setup.

这种场景的最佳工作流程是什么?

What's the best workflow for this scenario?

推荐答案

有一个新功能可以做到这一点,只需指定 local.gem_name 配置选项,例如:

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

这仅适用于 gem 具有在 Gemfile 中指定的 git 存储库和分支的情况.

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

有关详细信息,请参阅 Bundler 文档:http://bundler.io/v1.3/bundle_config.html

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

这篇关于在开发过程中如何配置 Bundler/Gemfile 以使用不同的 gem 源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆