Module: Zeitwerk::ExplicitNamespace
- Extended by:
- RealModName
- Defined in:
- lib/zeitwerk/explicit_namespace.rb
Overview
Centralizes the logic for the trace point used to detect the creation of explicit namespaces, needed to descend into matching subdirectories right after the constant has been defined.
The implementation assumes an explicit namespace is managed by one loader. Loaders that reopen namespaces owned by other projects are responsible for loading their constant before setup. This is documented.
Class Attribute Summary collapse
-
.cpaths ⇒ Object
readonly
Maps constant paths that correspond to explicit namespaces according to the file system, to the loader responsible for them.
- .mutex ⇒ Object readonly
- .tracer ⇒ Object readonly
Class Method Summary collapse
-
.register(cpath, loader) ⇒ Object
Asserts ‘cpath` corresponds to an explicit namespace for which `loader` is responsible.
- .unregister_loader(loader) ⇒ Object
Methods included from RealModName
Class Attribute Details
.cpaths ⇒ Object (readonly)
Maps constant paths that correspond to explicit namespaces according to the file system, to the loader responsible for them.
20 21 22 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 20 def cpaths @cpaths end |
.mutex ⇒ Object (readonly)
24 25 26 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 24 def mutex @mutex end |
.tracer ⇒ Object (readonly)
28 29 30 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 28 def tracer @tracer end |
Class Method Details
.register(cpath, loader) ⇒ Object
Asserts ‘cpath` corresponds to an explicit namespace for which `loader` is responsible.
35 36 37 38 39 40 41 42 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 35 def register(cpath, loader) mutex.synchronize do cpaths[cpath] = loader # We check enabled? because, looking at the C source code, enabling an # enabled tracer does not seem to be a simple no-op. tracer.enable unless tracer.enabled? end end |
.unregister_loader(loader) ⇒ Object
46 47 48 49 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 46 def unregister_loader(loader) cpaths.delete_if { |_cpath, l| l == loader } disable_tracer_if_unneeded end |