Hanami offers fast code reloading in development via the hanami-reloader gem.

When you run hanami server in development, guard watches the file system for code edits and restarts the Hanami server when changes occur.

Which directories are watched can be configured in the Guardfile of your project.

  1. # Guardfile
  2. group :server do
  3. guard "puma", port: ENV["HANAMI_PORT"] || 2300 do
  4. watch(%r{config/*})
  5. watch(%r{lib/*})
  6. watch(%r{app/*})
  7. watch(%r{slices/*})
  8. end
  9. end

Hanami takes an “outside the framework” approach to code reloading. This has several advantages:

  • file system watching is delegated to guard.
  • Hanami internals are free from code reloading awareness.
  • if the hanami-reloader gem is not present (which is true in production), code reloading logic is eliminated.

Thanks to Zeitwerk and lazy loading, code reloading is also very fast.

Reloading in the console

If you have an existing console session and make a code change, you can use your updated code via the reload helper:

  1. bundle exec hanami console
  2. bookshelf[development]> reload
  3. Reloading...