Skip to content

Commit

Permalink
Improves internal docs for explicit namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Oct 12, 2024
1 parent 4e37814 commit 15282c1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/zeitwerk/explicit_namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ module Zeitwerk
# loading their constant before setup. This is documented.
module ExplicitNamespace # :nodoc: all
# Maps cnames or cpaths of explicit namespaces with their corresponding
# loader. They are symbols if the namespace lives in Object, or qualified
# paths as strings otherwise. Entries are added as the namespaces are found,
# and removed as they are autoloaded.
# loader. They are symbols for top-level ones, and strings for nested ones:
#
# {
# :Admin => #<Zeitwerk::Loader:...>,
# "Hotel::Pricing" => #<Zeitwerk::Loader:...>
# }
#
# There are two types of keys to make loader_for as fast as possible, since
# it is invoked by our const_added for all autoloads and constant actually
# added. Globally. With this trick, for top-level constants we do not need
# to call Symbol#name and perform a string lookup. Instead, we can directly
# perform a fast symbol lookup.
#
# Entries are added as the namespaces are found, and removed as they are
# autoloaded.
#
# @sig Hash[(Symbol | String) => Zeitwerk::Loader]
@loaders = {}
Expand All @@ -32,7 +44,7 @@ class << self
end
end

# @sig (String) -> Zeitwerk::Loader?
# @sig (Module, Symbol) -> Zeitwerk::Loader?
internal def loader_for(mod, cname)
if Object.equal?(mod)
@loaders.delete(cname)
Expand Down

0 comments on commit 15282c1

Please sign in to comment.