On a recent project, we built a Sinatra mock API. A feature we added early on was hot code reloading via the rerun gem. Every time a file in the API changes, Sinatra automatically restarts.
It’s a nice system but not perfect, because the server restarts on changes to any file ending in
.md, and number of other extensions. This captures the
README, integration tests, and other undesirables, slowing everything down for no particular reason.
--dir flag scopes it to just files in the given directory. We chose the
src/ directory, which includes the API, mock database, and helpers.
$ rerun --dir src "ruby src/mock_api.rb"