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) ⇒ 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.
18 19 20 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 18 def cpaths @cpaths end |
.mutex ⇒ Object (readonly)
22 23 24 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 22 def mutex @mutex end |
.tracer ⇒ Object (readonly)
26 27 28 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 26 def tracer @tracer end |
Class Method Details
.register(cpath, loader) ⇒ Object
Asserts ‘cpath` corresponds to an explicit namespace for which `loader` is responsible.
33 34 35 36 37 38 39 40 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 33 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) ⇒ Object
44 45 46 47 |
# File 'lib/zeitwerk/explicit_namespace.rb', line 44 def unregister(loader) cpaths.delete_if { |_cpath, l| l == loader } disable_tracer_if_unneeded end |