Using a locally developed rubygem with Bundler
I was working with the Embedly API earlier on and thought I’d extract my code into a rubygem (released as tinyembedly, source on github). Preparing the gem was pretty straightforward (thanks to New gem with bundler) however getting the gem back into the ‘host’ application was proving difficult.
The problem I was trying to solve: I wanted to test my gem locally before pushing it out into the real world.
To do that, I thought I’d have to update Bundler to point to my local .gem file.
I added the gem to my Gemfile:
gem :tinyembedly, '0.0.1', :path => ~/dev/tinyembedly/pkg/tinyembedly-0.0.1.gem
Bundler couldn’t find the gem. Strange. After a bit of reading I updated my Gemfile to reference the .gem file folder instead.
gem :tinyembedly, '0.0.1', :path => ~/dev/tinyembedly/pkg/
Now, Bundler was more content, but I just couldn’t get my gem to require. A quick look at the $LOAD_PATH:
$LOAD_PATH.grep(/tiny/)
This revealed that instead of using the .gem file (as I thought) it was expecting :path to point to the unpacked .gem. Duh.
The solution had been staring me in the face. If I wanted to use the locally developed gem (before it had been uploaded to rubygems) I simply installed it, locally, and then added it to my Gemfile:
rake install
Updated my Gemfile:
gem 'tinyembedly', '0.0.1'
This works, because Bundler checks rubygems for the gem and when that fails, checks locally afterward. And with that, all was well. Huff.