Write to output, rather than below it - #19
Merged
Merged
Conversation
`output` used to be a root the namespace was appended to, so the tree landed at `output/<modules as a path>`. That inferred a file layout from a namespace, which only works if `output` is an autoload root, and it forced the generated tree into a directory of its own since the generator claimed everything under `output`. Now `output` is the directory, `modules` only decides what the files declare, and whether the two line up for Zeitwerk is the caller's call. The generated tree can sit beside the hand-written code implementing it. `module_path` stays for Rails routing, where `to:` takes a constant path rather than a file path. That leaves nowhere for the namespace file: Zeitwerk wants `Petstore::V1` in `v1.rb`, which now falls outside `output`, and the generator owning a file it does not live in was not worth the accessor sitting on the namespace. `Registry` holds itself instead, as a class-level `instance`/`instance=` over `@instance`, so `registry.rb` carries both the struct and the slot and no constant exists solely to hold it. A verb was tried first and dropped. `resolve` takes a key everywhere it appears — Laravel, dry-container, Autofac — and this takes no input; `bind` and `register` both imply one keyed entry among many, where this replaces the whole struct once per boot. A plain setter says there is one of these without implying a collection. Golden output is otherwise unchanged: the fixtures point `output` at the directory the old convention produced.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
outputis now the exact directory, not a root the namespace is appended to. Nothing is written outside it, and whether the path lines up withmodulesfor Zeitwerk is the caller's call.The namespace file
<output>.rbwould fall outsideoutput, soRegistryholds itself:Registry.instance = Registry.new(...)at boot,Registry.instancein a controller.To action: point
outputat the directory the old convention produced (app/api+[Petstore, V1]becomesapp/api/petstore/v1), and change the initializer to assignRegistry.instance.