How to use a personal gem built on top of a gem when creating another gem

If I have built a private gem (for example hosted inside my company) then I want to reuse that gem in another gem (not an application!) That I create, how do I do that?

Where can I place my dependencies and tell my new stone how to find the old (already built) personal stone?

+3


source to share


1 answer


So it took me a while to figure it out, because the answer is: it's in two places. Do it:

  • In your Gem Gemfile (yes Gemfile, not .gemspec) add the source line for your private server gem. If you also pull out RubyGems then it will 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 mynewgem.gemspec enter 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 obviously obvious: your Gemfile specifies the origin for your gems, and your .gemspec specifies the dependencies.

Hope this saves someone a few minutes.

+5


source







All Articles