This extension is part of the Sinatra::Contrib project. Run gem install sinatra-contrib to have it available.
Sinatra::Reloader
Extension to reload modified files. Useful during development, since it will automatically require files defining routes, filters, error handlers and inline templates, with every incoming request, but only if they have been updated.
Usage
Classic Application
To enable the reloader in a classic application all you need to do is require it:
require "sinatra" require "sinatra/reloader" if development? # Your classic application code goes here...
Modular Application
To enable the reloader in a modular application all you need to do is require it, and then, register it:
require "sinatra/base"
require "sinatra/reloader"
class MyApp < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
# Your modular application code goes here...
endChanging the Reloading Policy
You can refine the reloading policy with also_reload and dont_reload, to customize which files should, and should not, be reloaded, respectively.
Classic Application
Simply call the methods:
require "sinatra" require "sinatra/reloader" if development? also_reload '/path/to/some/file' dont_reload '/path/to/other/file' # Your classic application code goes here...
Modular Application
Call the methods inside the configure block:
require "sinatra/base"
require "sinatra/reloader"
class MyApp < Sinatra::Base
configure :development do
register Sinatra::Reloader
also_reload '/path/to/some/file'
dont_reload '/path/to/other/file'
end
# Your modular application code goes here...
end
Sinatra