Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
753 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...