zeitwerk 2.6.11 → 2.6.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0dd43924a88fceee915258e119a02df8fb173199576f52cf18c8298aab091361
4
- data.tar.gz: 6aeeced1ce99e28238ebd1488a543da6ba4fb885e283f999cec30a49db3a0ccf
3
+ metadata.gz: 5a9048a5ba05f448e5406080995aab9709a3dd7c8dd32aad3aa0ba4f544b69c4
4
+ data.tar.gz: 581cf27f70c82b754a1baadf7a41f6c87c069ae2e78bd26b4ec6e02cfa2795b9
5
5
  SHA512:
6
- metadata.gz: ca6b895667327b79fe51d504de760150aeceba5edb64400a6976962c1241bb8061f5c29e4d8584ba888694a0b1b30cf2f149f66f52181089fda262dde541d902
7
- data.tar.gz: 8393b41bda4187ce0195ce5b1192455a2bc574291188b0eba86f31af88fc66e3d441717823ac07407f8c7be4e4a97de06cb5bc1922a133e66ed51cc91f6eb1c7
6
+ metadata.gz: 45327b148bab210d941ffeae022b70e5c2f2be4372f2192a08859faeed81d2cc5702b05d6e4efcf676a8fb7b451c46200ac372051c68ba84cfc31ed9339f3ede
7
+ data.tar.gz: 8e3266d7641f58b6a8f74abfa913c14ae4a79d4efd177578de4e7e144a21adc33d33279b7d2771cdc57937cfedfb1f5e193bb9e57c18ea90956b342b516e9bd9
@@ -28,10 +28,10 @@ module Kernel
28
28
  if loader = Zeitwerk::Registry.loader_for(path)
29
29
  if path.end_with?(".rb")
30
30
  required = zeitwerk_original_require(path)
31
- loader.on_file_autoloaded(path) if required
31
+ loader.__on_file_autoloaded(path) if required
32
32
  required
33
33
  else
34
- loader.on_dir_autoloaded(path)
34
+ loader.__on_dir_autoloaded(path)
35
35
  true
36
36
  end
37
37
  else
@@ -39,7 +39,7 @@ module Kernel
39
39
  if required
40
40
  abspath = $LOADED_FEATURES.last
41
41
  if loader = Zeitwerk::Registry.loader_for(abspath)
42
- loader.on_file_autoloaded(abspath)
42
+ loader.__on_file_autoloaded(abspath)
43
43
  end
44
44
  end
45
45
  required
@@ -2,12 +2,12 @@
2
2
 
3
3
  module Zeitwerk::Loader::Callbacks
4
4
  include Zeitwerk::RealModName
5
+ extend Zeitwerk::Internal
5
6
 
6
7
  # Invoked from our decorated Kernel#require when a managed file is autoloaded.
7
8
  #
8
- # @private
9
9
  # @sig (String) -> void
10
- def on_file_autoloaded(file)
10
+ internal def on_file_autoloaded(file)
11
11
  cref = autoloads.delete(file)
12
12
  cpath = cpath(*cref)
13
13
 
@@ -20,8 +20,16 @@ module Zeitwerk::Loader::Callbacks
20
20
  else
21
21
  msg = "expected file #{file} to define constant #{cpath}, but didn't"
22
22
  log(msg) if logger
23
+
24
+ # Ruby still keeps the autoload defined, but we remove it because the
25
+ # contract in Zeitwerk is more strict.
23
26
  crem(*cref)
27
+
28
+ # Since the expected constant was not defined, there is nothing to unload.
29
+ # However, if the exception is rescued and reloading is enabled, we still
30
+ # need to deleted the file from $LOADED_FEATURES.
24
31
  to_unload[cpath] = [file, cref] if reloading_enabled?
32
+
25
33
  raise Zeitwerk::NameError.new(msg, cref.last)
26
34
  end
27
35
  end
@@ -29,9 +37,8 @@ module Zeitwerk::Loader::Callbacks
29
37
  # Invoked from our decorated Kernel#require when a managed directory is
30
38
  # autoloaded.
31
39
  #
32
- # @private
33
40
  # @sig (String) -> void
34
- def on_dir_autoloaded(dir)
41
+ internal def on_dir_autoloaded(dir)
35
42
  # Module#autoload does not serialize concurrent requires in CRuby < 3.2, and
36
43
  # we handle directories ourselves without going through Kernel#require, so
37
44
  # the callback needs to account for concurrency.
@@ -74,7 +81,7 @@ module Zeitwerk::Loader::Callbacks
74
81
  def on_namespace_loaded(namespace)
75
82
  if dirs = namespace_dirs.delete(real_mod_name(namespace))
76
83
  dirs.each do |dir|
77
- set_autoloads_in_dir(dir, namespace)
84
+ define_autoloads_for_dir(dir, namespace)
78
85
  end
79
86
  end
80
87
  end
@@ -171,7 +171,7 @@ module Zeitwerk::Loader::EagerLoad
171
171
  next if honour_exclusions && eager_load_exclusions.member?(abspath)
172
172
 
173
173
  if ruby?(abspath)
174
- if (cref = autoloads[abspath]) && !shadowed_file?(abspath)
174
+ if (cref = autoloads[abspath])
175
175
  cget(*cref)
176
176
  end
177
177
  else
@@ -121,7 +121,7 @@ module Zeitwerk
121
121
  break if @setup
122
122
 
123
123
  actual_roots.each do |root_dir, root_namespace|
124
- set_autoloads_in_dir(root_dir, root_namespace)
124
+ define_autoloads_for_dir(root_dir, root_namespace)
125
125
  end
126
126
 
127
127
  on_setup_callbacks.each(&:call)
@@ -407,14 +407,14 @@ module Zeitwerk
407
407
  end
408
408
 
409
409
  # @sig (String, Module) -> void
410
- private def set_autoloads_in_dir(dir, parent)
410
+ private def define_autoloads_for_dir(dir, parent)
411
411
  ls(dir) do |basename, abspath|
412
412
  if ruby?(basename)
413
413
  basename.delete_suffix!(".rb")
414
414
  autoload_file(parent, cname_for(basename, abspath), abspath)
415
415
  else
416
416
  if collapse?(abspath)
417
- set_autoloads_in_dir(abspath, parent)
417
+ define_autoloads_for_dir(abspath, parent)
418
418
  else
419
419
  autoload_subdir(parent, cname_for(basename, abspath), abspath)
420
420
  end
@@ -443,12 +443,12 @@ module Zeitwerk
443
443
  elsif !cdef?(parent, cname)
444
444
  # First time we find this namespace, set an autoload for it.
445
445
  namespace_dirs[cpath(parent, cname)] << subdir
446
- set_autoload(parent, cname, subdir)
446
+ define_autoload(parent, cname, subdir)
447
447
  else
448
448
  # For whatever reason the constant that corresponds to this namespace has
449
449
  # already been defined, we have to recurse.
450
450
  log("the namespace #{cpath(parent, cname)} already exists, descending into #{subdir}") if logger
451
- set_autoloads_in_dir(subdir, cget(parent, cname))
451
+ define_autoloads_for_dir(subdir, cget(parent, cname))
452
452
  end
453
453
  end
454
454
 
@@ -471,7 +471,7 @@ module Zeitwerk
471
471
  shadowed_files << file
472
472
  log("file #{file} is ignored because #{cpath(parent, cname)} is already defined") if logger
473
473
  else
474
- set_autoload(parent, cname, file)
474
+ define_autoload(parent, cname, file)
475
475
  end
476
476
  end
477
477
 
@@ -485,12 +485,12 @@ module Zeitwerk
485
485
 
486
486
  log("earlier autoload for #{cpath(parent, cname)} discarded, it is actually an explicit namespace defined in #{file}") if logger
487
487
 
488
- set_autoload(parent, cname, file)
488
+ define_autoload(parent, cname, file)
489
489
  register_explicit_namespace(cpath(parent, cname))
490
490
  end
491
491
 
492
492
  # @sig (Module, Symbol, String) -> void
493
- private def set_autoload(parent, cname, abspath)
493
+ private def define_autoload(parent, cname, abspath)
494
494
  parent.autoload(cname, abspath)
495
495
 
496
496
  if logger
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.6.11"
4
+ VERSION = "2.6.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeitwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.11
4
+ version: 2.6.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Noria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-02 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem