forked from ubicloud/ubicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Zeitwerk and rely on Unreloader only
As it turns out, Clover was started almost on the same day Unreloader got a release that implemented autoload functionality. Had it been around a bit longer, maybe I would have done things like this to begin with. As it turns out, we had some issues with Zeitwerk being a bit too clever -- or prescriptive -- about how it handled constants, and as a result, code reloading didn't quite work right. Now, this does: Unreloader.reload! Also somewhat less idiomatic to Unreloader vs. Zeitwerk is setting up autoload, and subsequently forcing them to load in production cases. Doing things this way frees Clover code from having to require dependencies within the project manually: otherwise, when Unreloader.autoload is switched to a "require" when `autoload: false` is passed, missing constant dependencies between files can crash. I considered whether we should abide the old Ruby ways and maintain a correct -- and, more difficult still, minimal -- require order embedded into each file, but decided the Zeitwerk style seemed more practical. Alternatively, I considered removing Unreloader in favor of Zeitwerk, but that seemed unappealing: the in-place reloading funcionality it was designed for with hash_branch and Roda is too good to give up. See jeremyevans/roda-sequel-stack#21. And Unreloader has some more advanced features that improve the quality of reloading if one is willing to write bespoke code to help Unreloader, which we are. One piece of errata: Zeitwerk is good about figuring out if a namespace should be a class or a module given files like this: a/dir/foo.rb a/dir.rb In this case, Zeitwerk will notice that A::Dir should be a class, not a module. The code I wrote here is not so smart: if the list of files is presented with a nested constant first, it'll create modules to contain it, even if later a class is found that should define the namespace. But right now, we don't have this ambiguity, so I figure we can solve it later as necessary.
- Loading branch information
Showing
6 changed files
with
79 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters