Tag Archives: geocoder

Loading Gem from Local Source

As a ruby programmer, we are treated with a rich ecosystem of library called the ruby gems.

Along the way, sometime you found a new need that can’t be fulfilled by your current gem choice. This happened to me last month with geocoder.

When this happens you have two choices:
1. Roll out your own solution from scratch
2. Patch the current gem so that it can solve your problem

From my case, I need to use Googe Places Search API for geocoding, that the geocoder didn’t support yet. I check that it is not difficult to patch the gem (not always the case) and my code base already uses the gem a lot, so I decided to patch the gem.

It might be confusing if this is the first time you want to patch a gem. How to do edit the files locally? Turns out it is quite easy.
First, fork the gem repository, and clone the fork to your local computer, for example to:


Then modify your project Gemfile to specify your local path:

# Gemfile
gem 'geocoder', path: '~/gempatch/geocoder'

Run bundle and voila! your project is running the gem from local source. Any modification you made on the gem locally will be immediately reflected on your project. Once you are happy with your modification, save and commit your change, and push it to the gem fork on your repository.

Now you can set your project to use the gem from your repository, so it will work in production

# Gemfile
gem 'geocoder', git: "git://github.com/waruboy/geocoder.git", branch: "place-search"

Oh, and please consider to create a Pull Request to the main repository of the gem. It’s a nice way to contribute to the community and also great to put your name out there. Just make sure to read if the gem have any contributing guidelines before doing so.

Happy patching!

PS. Thanks a lot for Tyler Tringas from Storemapper for sponsoring my contribution work to the Geocoder gem.