This is the result of a fair bit of testing and back-and-forth with ChatGPT to help me:
- Do local development on a gem for use with Rails apps
- Add the gem to a local Rails app I'm working on for testing
- Make changes to the gem
- See those changes reflected in the Rails app without having to restart the server each time
The solution is in two parts:
- Integrate Zeitwerk into the gem (not just making the filenaming compatible)
- Integrate the gem into the host Rails app's reloaders (but only if the Rails app is in
development mode, and if the gem was added to the Gemfile with a
path:
to the local copy of the gem
As an added bonus, the developer experience for the gem is pretty simple too:
- No need to manually require all the files in your gem (they're autoloaded when called)
- Classes and Modules are autoloaded in things like
bin/console
- Classes and Modules are autoloaded in your spec or test environment