All talk but no code...

makes lulalala a bluff boy

Gem development inside Rails app

| Comments

Often during app development, it's a good idea to extract some functionality into a gem. The simple way to do this is to open a new git repository, do a bundle gem foobar, publish it, install said gem inside Rails app, use it and test some more.

How about updates? We have to change the gem, guessing how it can be used inside Rails. Then release a version, install it inside your app, and finally do some testing. This is a lot of friction. This can be especially bad if your gem is closely coupled with the app, or gets updated a lot.

How about this?

  1. Create an empty gem (e.g. bundle gem foobar) (without doing any release)
  2. Push it onto Github.
  3. Put the gem in your Rails app as a submodule: git submodule add vendor/foobar
  4. Install the empty gem in your app's Gemfile: gem 'settei', path:'./vendor/foobar'
  5. ...
  6. Profit!

Now develop the gem entirely inside app's submodule. It's probably possible to autoload it (though I don't recommend it). This will also work in production too.


comments powered by Disqus