Milan
Milan

Reputation: 272

Bundling a forked gem inside a gem

I am trying to build a gem for a project that has a dependency on an unnamed external gem :)

During development I found a small bug in the external project and I added a one line fix that resolves it. I submitted a pull request on github, but I have no response from the maintainer for some time now.

I want to make my project available as a gem but it wont work without this fix. What can I do? What would be the best way to fix this.

One option I thought about was to create a gem of the forked project and publish it under a convoluted name, and make a dependency on that. But I don't like the idea of polluting the servers with such a stupid gem.

So I was wondering if it is possible to bundle the external gem into my application, and make it install together with my gem. What would be the cleanest and easiest way to do this?

Upvotes: 4

Views: 156

Answers (3)

Noah
Noah

Reputation: 516

Have you considered overriding the function with your own code? I was having a similar problem with some software at work a few weeks ago and I just redefined the function.

Since it was just one line you found, it seems like this would be the easiest solution, but I am a little bit new to Ruby so maybe there is a problem with this plan that I have not considered.

Upvotes: 2

Maurício Linhares
Maurício Linhares

Reputation: 40333

It's quite simple, in fact. In your Gemfile add the dependency as:

gem "nokogiri", :git => "git://github.com/tenderlove/nokogiri.git"

To do this you would also need to be using bundler to manage your gem, you can get more info on this here.

The other option is to add the code you changed to a vendor directory in your gem and distribute it with your code, this way you can just add the main directory of this other gem to your load path and you will be able to require it without any issues.

To add something to the load path you simply do:

$LOAD_PATH.unshift( File.join(File.dirname(__FILE__), '..', 'vendor', 'some_gem', 'lib') )

And you will be able to directly require files at some_gem.

Upvotes: 0

Michael Kohl
Michael Kohl

Reputation: 66837

You could publish it under a different name and once the upstream maintainer accepted your fix, you can yank your version.

Upvotes: 1

Related Questions