Вопрос

If I've built a private gem (hosted internally at my company, for instance), then I want to reuse that gem in another gem (not app!) that I'm building, how do I do that?

Where do I put my dependencies and tell my new gem how to find the old (already built) privately hosted gem?

Это было полезно?

Решение

So this took me awhile to figure out, because the answer is, it's in TWO places. Do this:

  • In your gem's Gemfile (yes, Gemfile, not .gemspec), add the source line for your private gem server. If you're also pulling from RubyGems, then it'll look something like this:
source 'http://rubygems.org'
source 'http://myrubygems.mycompany.example.com:8808'  # Or wherever your gems are hosted internally (or externally)
gemspec
  • Then, in your mynewgem.gemspec put the following:
Gem::Specification.new do |gem|
  # [...]
  gem.add_dependency 'myoldgem'  # the gem hosted at myrubygems.mycompany.example.com:8808
end

The reason this works is probably obvious: Your Gemfile specifies the source for your gems and your .gemspec specifies the dependencies.

Hope this saves someone a few minutes.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top