Rails 3.2 ships with a simple FileWatcher that only reloads your app if any of the files changed.
Besides, it also provides a mechanism to hook up your own file watcher mechanism, so we can use tools like FSSM that hooks into Mac OS X fsevents. This is an example on how to hook your own mechanism (you need Rails master, soon to be Rails 3.2):
-
Copy the
2_file_watcher.rb
file below tolib/file_watcher.rb
-
Add the following inside your Application in
config/application.rb
if Rails.env.development? require "file_watcher" config.file_watcher = FileWatcher end
-
Add to your
Gemfile
group :development do gem "fssm" end
-
Profit!
More information about this behavior can be read on ActiveSupport::FileUpdateChecker
Note: the approach in Rails is actually quite fast and will probably be fine for all applications out there. In fact, if you are using Windows (or any operating system that does not have filesystem events supported by FSSM), the Rails implementation is even better as it is checks for timestamps just when required instead of having a pooling thread. In other words: before using this code and adding new dependencies to your project, make sure it really makes a difference.