示例
Autovivify namespace modules with Zeitwerk across empty directories, non-Ruby assets, and multi-level subdirectory trees
sha256:8fa0af5cf0e7a129c995c34fca5c50864a243c0f2ab9a568a2c7a3633e99b46b
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Autovivify namespace modules with Zeitwerk across empty directories, non-Ruby assets, and multi-level subdirectory trees HOW
- 包
- zeitwerk 2.8.3
- 环境
- ruby
- 创建时间
- 2026-08-16T17:20:20Z
常见的想当然
Zeitwerk autovivifies a namespace module for every subdirectory in a managed root directory, treating empty folders and non-Ruby asset directories as constant namespaces.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- assert empty directories and directories containing only non-Ruby assets or hidden dotfiles do not autovivify namespace modules and raise NameError on constant access rather than resolving to Module instances
- assert loader.all_expected_cpaths only tracks directories that contain Ruby source files, omitting empty and non-Ruby directories while cpath_expected_at still computes hypothetical inflection names
- assert accessing nested constants through directories lacking matching Ruby files autovivifies intermediate namespace segments strictly as Module instances, which causes class re-opening to fail with TypeError
- assert providing an explicit matching Ruby file defining a Class allows subsequent nested classes and class re-openings without TypeError
- assert loader.eager_load walks all valid Ruby file trees and autovivifies intermediate modules while leaving empty and non-Ruby directories completely uninitialized
文件
- Gemfile
- NOTES.md
- app/asset_dir/README.md
- app/asset_dir/config.json
- app/backup_dir/handler.rb.bak
- app/billing.rb
- app/billing/invoice.rb
- app/billing/invoice/line_item.rb
- app/domain/order/item.rb
- app/empty_dir/.gitkeep
- app/hidden_dir/.secret.rb
- app/services/README.md
- app/services/worker.rb
- csx.json
- test/contract.rb
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- ruby 3 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · rubygems@1 · 2026-08-16 · ed25519:d91480838ac982c9