lib/zeitwerk/explicit_namespace.rb in zeitwerk-2.4.0 vs lib/zeitwerk/explicit_namespace.rb in zeitwerk-2.4.1
- old
+ new
@@ -12,50 +12,51 @@
# Maps constant paths that correspond to explicit namespaces according to
# the file system, to the loader responsible for them.
#
# @private
- # @return [{String => Zeitwerk::Loader}]
+ # @sig Hash[String, Zeitwerk::Loader]
attr_reader :cpaths
# @private
- # @return [Mutex]
+ # @sig Mutex
attr_reader :mutex
# @private
- # @return [TracePoint]
+ # @sig TracePoint
attr_reader :tracer
# Asserts `cpath` corresponds to an explicit namespace for which `loader`
# is responsible.
#
# @private
- # @param cpath [String]
- # @param loader [Zeitwerk::Loader]
- # @return [void]
+ # @sig (String, Zeitwerk::Loader) -> void
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
# @private
- # @param loader [Zeitwerk::Loader]
- # @return [void]
+ # @sig (Zeitwerk::Loader) -> void
def unregister(loader)
cpaths.delete_if { |_cpath, l| l == loader }
disable_tracer_if_unneeded
end
+ private
+
+ # @sig () -> void
def disable_tracer_if_unneeded
mutex.synchronize do
tracer.disable if cpaths.empty?
end
end
+ # @sig (TracePoint) -> void
def tracepoint_class_callback(event)
# If the class is a singleton class, we won't do anything with it so we
# can bail out immediately. This is several orders of magnitude faster
# than accessing its name.
return if event.self.singleton_class?