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

问题描述

我有一个Sinatra应用程序,需要在本地开发另一个宝石。我无法在开发过程中配置Bundler使用我的本地创业板代码,但是我的创业宝石代码正在制作中。



理想情况下,我可以这样做,但Bundler不会'您可以指定相同的gem两次:

 #不工作:
group:development do
gem'awesome',:path => 〜/ code / awesome
end

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

与此同时,已经诉诸手工售卖宝石&每次部署时更新Gemfile中的Gem源代码,这非常麻烦。我的工作流程是这样的:
$ b $ ol <

  • 在开发过程中指向我的本地gem( gem'awesome',:path => ;〜/ code / awesome

  • 准备部署时,将gem解包为 vendor / gems

  • 更新Gemfile以指向出售的gem( gem'awesome',:path =>vendor / gems / awesome-0.0.1
  • 运行 bundle install (更新Gemfile.lock)

  • 部署代码
  • 返回步骤1。

  • 真是麻烦!我希望做一些比简单编写Rake任务来更自动化当前设置的工作。



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

    解决方案

    有一项新功能可以通过简单描述 local.gem_name config选项,例如:

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



    这只适用于gem在Gemfile中指定了git repo和branch。



    有关更多详细信息,请参阅Bundler文档:


    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.

    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
    

    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. 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.

    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?

    解决方案

    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

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

    09-23 10:23