0

I've been creating a rubygem ( lets call it 'abc' ) that relies on other gems.

As my development progressed I discovered I needed to make changes to the gems I depended on. So I forked them on github and added them to my Gemfile.

source 'https://rubygems.org'

gem 'xxx', '~> 0.0.6',  :git => 'https://github.com/poulh/xxx.git'
gem 'yyy', '~> 0.8.2', :git => 'https://github.com/poulh/yyy.git'
gem 'zzz', '~> 0.0.14', :git => 'https://github.com/poulh/zzz.git'

I then used bundle install and added this line to lib/abc.rb in my gem's directory

require 'bundler/setup'
require 'xxx'
require 'yyy'
require 'zzz'

This worked and I could continue my development.

Now my gem is complete and I want to publish it to rubygems.org.

However I need the custom changes I made to the above gems, and I cannot get a response from the owner's when I did a pull-request to merge in my changes.

Ideally users of my gem can just run

gem install abc

and they'll be on their way, but when I test this the gem won't work without also

  • cloning abc's repo
  • running bundle install

can these extra steps be avoided?

Poul
  • 3,426
  • 5
  • 37
  • 43

1 Answers1

2

As you can read about in this article, putting your gem's dependencies in its Gemfile is not the right way. Rather, you should put the gemspec line in the Gemfile which directs it to read from the gemspec file. Think about the Gemfile as being for development only - when you push the gem, the gemspec alone becomes the specification for dependencies.

And, as you can read here, it is not possible to put a git source in the gemspec.

In light of this, my recommendation would be to move the forked gem's source code into your file and add it's dependencies to your gemspec. Usurp it, in other words - make it part of your project.

You could also specify in your README that users should add this separate gem to their Gemfile, sourced from git. That's easier for you but adds another step to the installation process.

Community
  • 1
  • 1
max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • Although I largely agree, using forked gems is always a difficult thing to manage, and even more difficult to sell. Ideally you get these gems fixed so they're compatible as-is and you can do a straight dependency. – tadman Feb 22 '17 at 23:34
  • Thank you for the comments. I ended up forking the gems ( they hadn't been updated in years ) and making my own versions on rubygems.org – Poul Feb 24 '17 at 19:37