Using platform dependent gems: rb-inotify and rb-fsevent

Update: We are now using the gem Listen from the folks behind Guard which works across platforms. It is a better solution than the one below.

We, here at SupportBee all use a Mac. It is a great developer machine especially for a Ruby on Rails developer (RoR + RVM + HomeBrew FTW! ) Our server run on debian on a Hetzner stack.

We are constantly improving out backend architecture and during the recent update we hit a roadblock. The update required the use of inotify for monitoring file system events. There are many ruby wrappers available including rb-inotify and rb-fsevent for Linux and Mac respectively. We need to require one of these depending on the OS platform. The problem is adding the gem dependency to the Gemfile. We use the Gemfile.lock file generated by Bundler during deploy. Adding a conditional gem dependency will create an unstable Gemfile.lock.

This is a know issue in Bundler and the answers to this stackoverflow question provide the possible workarounds:

We did not want to mess around with the Gemfile.lock, so we decided to add the gems to different groups depending on the platforms on which the envirnoments are usually used.

The key here is to pass the require => false option in the Gemfile to avoid Bundler failing on LoadError. The other issue is these two gems have a slightly different APIs. We had to write a proxy to address this issue. The following piece of code does exactly that. Its been tested on Mac Lion and Debian Squeeze.


This is a simple wrapper. Please feel free to fork and update to support further options.

blog comments powered by Disqus
Avinasha Shastry
Avinasha Shastry