Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to handle bug fixes in a gem dependency?

Tags:

ruby

rubygems

I have a gem (available on RubyGems) that relies on another gem. That dependent gem has a bug which I fixed recently. Unfortunately, that dependent gem is pretty much dead; it hasn't seen an update in years, and the owner isn't active on GitHub anymore at all, let alone making commits to this gem, so I don't expect my patch will get accepted—certainly not any time soon.

In light of that, what's the best way to handle the patched version of this dependent gem? Do I fork it and upload a new gem (with a new name) to RubyGems, and depend on that? Do I package my fixed version with my own gem somehow?

like image 239
mipadi Avatar asked Sep 16 '16 00:09

mipadi


1 Answers

First of all check the bugged gem's LICENSE (and your code's license, too - be sure things stay compatible).

Then - as you stated - you have multiple options:

  • Include the fixed gem in your project and tell bundler/Gemfile to use the gem from that place.
  • Fork, fix and tell bundler/Gemfile to use your git repository.
  • Fork, fix and re-release (thats the upstream variant, embracing Open Source and its community).
  • Monkey-Patching at runtime might be a solution, too (depends a bit on the code in question and your code-smell-tolerance. Basically: Don't do this at home! Leave alone, at work!).

I'd go with the the fork, fix and re-release solution, but you might have to make clear (in the README) that this gem needs a new maintainer.

It depends on what you mean with "best" (...whats the best way...). Easiest would probably be to monkey-patch, second to include the gem in your repository and tell bundler/Gemfile to pick it up from there. Also, no weird gem update will break your code. But then, if there ever should be fixes (by people like you :) ), you'll miss out on them.

like image 188
Felix Avatar answered Nov 10 '22 22:11

Felix