lib/zeitwerk/loader/callbacks.rb in zeitwerk-2.6.6 vs lib/zeitwerk/loader/callbacks.rb in zeitwerk-2.6.7
- old
+ new
@@ -9,21 +9,21 @@
# @sig (String) -> void
def on_file_autoloaded(file)
cref = autoloads.delete(file)
cpath = cpath(*cref)
- # If reloading is enabled, we need to put this constant for unloading
- # regardless of what cdef? says. In Ruby < 3.1 the internal state is not
- # fully cleared. Module#constants still includes it, and you need to
- # remove_const. See https://github.com/ruby/ruby/pull/4715.
- to_unload[cpath] = [file, cref] if reloading_enabled?
Zeitwerk::Registry.unregister_autoload(file)
if cdef?(*cref)
log("constant #{cpath} loaded from file #{file}") if logger
+ to_unload[cpath] = [file, cref] if reloading_enabled?
run_on_load_callbacks(cpath, cget(*cref), file) unless on_load_callbacks.empty?
else
- raise Zeitwerk::NameError.new("expected file #{file} to define constant #{cpath}, but didn't", cref.last)
+ msg = "expected file #{file} to define constant #{cpath}, but didn't"
+ log(msg) if logger
+ crem(*cref)
+ to_unload[cpath] = [file, cref] if reloading_enabled?
+ raise Zeitwerk::NameError.new(msg, cref.last)
end
end
# Invoked from our decorated Kernel#require when a managed directory is
# autoloaded.