Skip to content

Write to output, rather than below it - #19

Merged
Jack97 merged 1 commit into
masterfrom
jr/output-is-the-root
Sep 16, 2026
Merged

Jack97 merged 1 commit into
masterfrom
jr/output-is-the-root

Conversation

@Jack97

@Jack97 Jack97 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator
output: app/api/petstore/v1   # where the tree goes
modules: [Petstore, V1]       # what it declares

output is now the exact directory, not a root the namespace is appended to. Nothing is written outside it, and whether the path lines up with modules for Zeitwerk is the caller's call.

The namespace file <output>.rb would fall outside output, so Registry holds itself: Registry.instance = Registry.new(...) at boot, Registry.instance in a controller.

To action: point output at the directory the old convention produced (app/api + [Petstore, V1] becomes app/api/petstore/v1), and change the initializer to assign Registry.instance.

`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.
@Jack97
Jack97 merged commit e7d2ec9 into master Sep 16, 2026
10 checks passed
@Jack97
Jack97 deleted the jr/output-is-the-root branch September 16, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant