While developing Sinatra applications, to reload changed files I’ve been stopping the server (Ctrl C) and restarting it (Rackup), wasting precious time with every change. Today I finally went ahead and added the Reloader extension. Here is how:
Install the gem on your machine (I didn’t add it to the Gemfile since I don’t need it on production):
$ gem install sinatra-contrib
For the simple wedding website that I am working on, a classic Sinatra application, I’m simply requiring it through:
require "sinatra/reloader" if development?
For the modular application that I’m building at work, I added the following code to require it:
require "sinatra/reloader"
class MyApp < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
end
That’s it! Either application will now reload the changed files with every incoming request. If you need to restart the HTTP server on every request check out shotgun.
Sources:
What happened to reloading in Sinatra 0.9.2?: http://www.sinatrarb.com/faq.html#reloading
Sinatra::Reloader: http://www.sinatrarb.com/contrib/reloader
Shotgun: http://rtomayko.github.com/shotgun/