zeitwerk 2.6.5 → 2.6.7

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: 6811a58f4992b66a3625b1b931f070463619e806c0e044611df1f706a0cb1477
4
- data.tar.gz: 07dd0a9133025560ad914dca656d0ed1044cc791d6e09586dbd03c0a72929751
3
+ metadata.gz: e6c7bf12c3a33195c57541b840ca6d7dbc21b19e0d7b91d8933ad37aa88b325d
4
+ data.tar.gz: 4b8dd86417dd633b78c02eada9ed6956e8e708397c988237aaddecb9644ba469
5
5
  SHA512:
6
- metadata.gz: 0a360aad989a229b0a315d6d38690401f18ef55b45e8ae30e05db81eb85f9954f8ec1e4fa738b774175c06736f44bcecf2dcfbca74b7d79a049d59071489a7b9
7
- data.tar.gz: 851ecb2490e716aac571f140f51bedbaf1f1eb99761d1c98a9afe1982099bddc9455efedcd243ff770b7d08c616dd48efce20a7e2378e41ef2844e197cc085f2
6
+ metadata.gz: 4f0bc60d9914a9e815aed501a030f7e9bde7927f750f3836f96ac86a52c0699f4ca69456bd381845428f6b09adccaa085443f39bb0fdaa651437742e21d10af2
7
+ data.tar.gz: 3ba55f7bb24725d156cc4043697bfcd6092e2893f1aa71296965c82ae9ed66b79c30f853b535693b6b884d7d3d26cf1b122545e395ba11c92f65552e14116248
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
 
5
5
  [![Gem Version](https://img.shields.io/gem/v/zeitwerk.svg?style=for-the-badge)](https://rubygems.org/gems/zeitwerk)
6
- [![Build Status](https://img.shields.io/github/workflow/status/fxn/zeitwerk/CI?event=push&style=for-the-badge)](https://github.com/fxn/zeitwerk/actions?query=event%3Apush)
6
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/fxn/zeitwerk/ci.yml?branch=main&event=push&style=for-the-badge)](https://github.com/fxn/zeitwerk/actions/workflows/ci.yml?query=branch%3main)
7
7
 
8
8
  <!-- TOC -->
9
9
 
@@ -58,9 +58,6 @@
58
58
  - [Encodings](#encodings)
59
59
  - [Rules of thumb](#rules-of-thumb)
60
60
  - [Debuggers](#debuggers)
61
- - [debug.rb](#debugrb)
62
- - [Byebug](#byebug)
63
- - [Break](#break)
64
61
  - [Pronunciation](#pronunciation)
65
62
  - [Supported Ruby versions](#supported-ruby-versions)
66
63
  - [Testing](#testing)
@@ -176,7 +173,7 @@ class HttpCrawler
176
173
  end
177
174
  ```
178
175
 
179
- The first example needs a custom [inflection](https://github.com/fxn/zeitwerk#inflection) rule:
176
+ The first example needs a custom [inflection](#inflection) rule:
180
177
 
181
178
  ```ruby
182
179
  loader.inflector.inflect("max_retries" => "MAX_RETRIES")
@@ -391,6 +388,12 @@ module MyGem
391
388
  end
392
389
  ```
393
390
 
391
+ Due to technical reasons, the entry point of the gem has to be loaded with `Kernel#require`, which is the standard way to load a gem. Loading that file with `Kernel#load` or `Kernel#require_relative` won't generally work.
392
+
393
+ `Zeitwerk::Loader.for_gem` is idempotent when invoked from the same file, to support gems that want to reload (unlikely).
394
+
395
+ If the entry point of your gem lives in a subdirectory of `lib` because it is reopening a namespace defined somewhere else, please use the generic API to setup the loader, and make sure you check the section [_Reopening third-party namespaces_](#reopening-third-party-namespaces) down below.
396
+
394
397
  Loaders returned by `Zeitwerk::Loader.for_gem` issue warnings if `lib` has extra Ruby files or directories.
395
398
 
396
399
  For example, if the gem has Rails generators under `lib/generators`, by convention that directory defines a `Generators` Ruby module. If `generators` is just a container for non-autoloadable code and templates, not acting as a project namespace, you need to setup things accordingly.
@@ -407,10 +410,6 @@ Otherwise, there's a flag to say the extra stuff is OK:
407
410
  Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
408
411
  ```
409
412
 
410
- This method is idempotent when invoked from the same file, to support gems that want to reload (unlikely).
411
-
412
- If the entry point of your gem lives in a subdirectory of `lib` because it is reopening a namespace defined somewhere else, please use the generic API to setup the loader, and make sure you check the section [_Reopening third-party namespaces_](https://github.com/fxn/zeitwerk#reopening-third-party-namespaces) down below.
413
-
414
413
  <a id="markdown-autoloading" name="autoloading"></a>
415
414
  ### Autoloading
416
415
 
@@ -445,7 +444,7 @@ loader.eager_load
445
444
 
446
445
  That skips [ignored files and directories](#ignoring-parts-of-the-project).
447
446
 
448
- In gems, the method needs to be invoked after the main namespace has been defined, as shown in [Synopsis](https://github.com/fxn/zeitwerk#synopsis).
447
+ In gems, the method needs to be invoked after the main namespace has been defined, as shown in [Synopsis](#synopsis).
449
448
 
450
449
  Eager loading is synchronized and idempotent.
451
450
 
@@ -486,7 +485,7 @@ This is useful when the loader is not eager loading the entire project, but you
486
485
 
487
486
  Both strings and `Pathname` objects are supported as arguments. If the argument is not a directory managed by the receiver, the method raises `Zeitwerk::Error`.
488
487
 
489
- [Eager load exclusions](#eager-load-exclusions), [ignored files and directories](#ignoring-parts-of-the-project), and [shadowed files](https://github.com/fxn/zeitwerk#shadowed-files) are not eager loaded.
488
+ [Eager load exclusions](#eager-load-exclusions), [ignored files and directories](#ignoring-parts-of-the-project), and [shadowed files](#shadowed-files) are not eager loaded.
490
489
 
491
490
  `Zeitwerk::Loader#eager_load_dir` is idempotent, but compatible with reloading. If you eager load a directory and then reload, eager loading that directory will load its (current) contents again.
492
491
 
@@ -519,11 +518,11 @@ root_dir3/my_app/routes
519
518
 
520
519
  where `root_directory{1,2,3}` are root directories, eager loading `MyApp::Routes` will eager load the contents of the three corresponding directories.
521
520
 
522
- There might exist external source trees implementing part of the namespace. This happens routinely, because top-level constants are stored in the globally shared `Object`. It happens also when deliberately [reopening third-party namespaces](reopening-third-party-namespaces). Such external code is not eager loaded, the implementation is carefully scoped to what the receiver manages to avoid side-effects elsewhere.
521
+ There might exist external source trees implementing part of the namespace. This happens routinely, because top-level constants are stored in the globally shared `Object`. It happens also when deliberately [reopening third-party namespaces](#reopening-third-party-namespaces). Such external code is not eager loaded, the implementation is carefully scoped to what the receiver manages to avoid side-effects elsewhere.
523
522
 
524
523
  This method is flexible about what it accepts. Its semantics have to be interpreted as: "_If_ you manage this namespace, or part of this namespace, please eager load what you got". In particular, if the receiver does not manage the namespace, it will simply do nothing, this is not an error condition.
525
524
 
526
- [Eager load exclusions](#eager-load-exclusions), [ignored files and directories](#ignoring-parts-of-the-project), and [shadowed files](https://github.com/fxn/zeitwerk#shadowed-files) are not eager loaded.
525
+ [Eager load exclusions](#eager-load-exclusions), [ignored files and directories](#ignoring-parts-of-the-project), and [shadowed files](#shadowed-files) are not eager loaded.
527
526
 
528
527
  `Zeitwerk::Loader#eager_load_namespace` is idempotent, but compatible with reloading. If you eager load a namespace and then reload, eager loading that namespace will load its (current) descendants again.
529
528
 
@@ -576,7 +575,7 @@ loader.load_file("#{__dir__}/custom_web_app/routes.rb")
576
575
 
577
576
  This is useful when the loader is not eager loading the entire project, but you still need an individual file to be loaded for things to function properly.
578
577
 
579
- Both strings and `Pathname` objects are supported as arguments. The method raises `Zeitwerk::Error` if the argument is not a Ruby file, is [ignored](#ignoring-parts-of-the-project), is [shadowed](https://github.com/fxn/zeitwerk#shadowed-files), or is not managed by the receiver.
578
+ Both strings and `Pathname` objects are supported as arguments. The method raises `Zeitwerk::Error` if the argument is not a Ruby file, is [ignored](#ignoring-parts-of-the-project), is [shadowed](#shadowed-files), or is not managed by the receiver.
580
579
 
581
580
  `Zeitwerk::Loader#load_file` is idempotent, but compatible with reloading. If you load a file and then reload, a new call will load its (current) contents again.
582
581
 
@@ -951,6 +950,8 @@ However, sometimes it might still be convenient to tell Zeitwerk to completely i
951
950
 
952
951
  You can ignore file names, directory names, and glob patterns. Glob patterns are expanded when they are added and again on each reload.
953
952
 
953
+ There is an edge case related to nested root directories. Conceptually, root directories are independent source trees. If you ignore a parent of a nested root directory, the nested root directory is not affected. You need to ignore it explictly if you want it ignored too.
954
+
954
955
  Let's see some use cases.
955
956
 
956
957
  <a id="markdown-use-case-files-that-do-not-follow-the-conventions" name="use-case-files-that-do-not-follow-the-conventions"></a>
@@ -1085,8 +1086,9 @@ For technical reasons, raw constant assignment is not supported:
1085
1086
 
1086
1087
  ```ruby
1087
1088
  # trip.rb
1088
- Trip = Class.new { ... } # NOT SUPPORTED
1089
- Trip = Struct.new { ... } # NOT SUPPORTED
1089
+ Trip = Class { ...} # NOT SUPPORTED
1090
+ Trip = Struct.new { ... } # NOT SUPPORTED
1091
+ Trip = Data.define { ... } # NOT SUPPORTED
1090
1092
  ```
1091
1093
 
1092
1094
  This only affects explicit namespaces, those idioms work well for any other ordinary class or module.
@@ -1169,6 +1171,8 @@ loader.push_dir(Pathname.new("/bar"), namespace: Bar)
1169
1171
  loader.dirs(namespaces: true) # => { "/foo" => Object, "/bar" => Bar }
1170
1172
  ```
1171
1173
 
1174
+ By default, ignored root directories are filtered out. If you want them included, please pass `ignored: true`.
1175
+
1172
1176
  These collections are read-only. Please add to them with `Zeitwerk::Loader#push_dir`.
1173
1177
 
1174
1178
  <a id="markdown-encodings" name="encodings"></a>
@@ -1201,22 +1205,9 @@ The test suite passes on Windows with codepage `Windows-1252` if all the involve
1201
1205
  <a id="markdown-debuggers" name="debuggers"></a>
1202
1206
  ### Debuggers
1203
1207
 
1204
- <a id="markdown-debugrb" name="debugrb"></a>
1205
- #### debug.rb
1206
-
1207
- The new [debug.rb](https://github.com/ruby/debug) gem and Zeitwerk are mostly compatible. This is the new debugger that is going to ship with Ruby 3.1.
1208
-
1209
- There's one exception, though: Due to a technical limitation of tracepoints, explicit namespaces are not autoloaded while expressions are evaluated in the REPL. See [ruby/debug#408](https://github.com/ruby/debug/issues/408).
1210
-
1211
- <a id="markdown-byebug" name="byebug"></a>
1212
- #### Byebug
1213
-
1214
- Zeitwerk and [Byebug](https://github.com/deivid-rodriguez/byebug) have a similar edge incompatibility.
1215
-
1216
- <a id="markdown-break" name="break"></a>
1217
- #### Break
1208
+ Zeitwerk works fine with [debug.rb](https://github.com/ruby/debug) and [Break](https://github.com/gsamokovarov/break).
1218
1209
 
1219
- Zeitwerk works fine with [@gsamokovarov](https://github.com/gsamokovarov)'s [Break](https://github.com/gsamokovarov/break) debugger.
1210
+ [Byebug](https://github.com/deivid-rodriguez/byebug) is compatible except for an edge case explained in [deivid-rodriguez/byebug#564](https://github.com/deivid-rodriguez/byebug/issues/564).
1220
1211
 
1221
1212
  <a id="markdown-pronunciation" name="pronunciation"></a>
1222
1213
  ## Pronunciation
@@ -47,6 +47,13 @@ module Zeitwerk
47
47
  disable_tracer_if_unneeded
48
48
  end
49
49
 
50
+ # This is an internal method only used by the test suite.
51
+ #
52
+ # @sig (String) -> bool
53
+ internal def registered?(cpath)
54
+ cpaths.key?(cpath)
55
+ end
56
+
50
57
  # @sig () -> void
51
58
  private def disable_tracer_if_unneeded
52
59
  mutex.synchronize do
@@ -11,18 +11,18 @@ module Zeitwerk::Loader::Callbacks
11
11
  cref = autoloads.delete(file)
12
12
  cpath = cpath(*cref)
13
13
 
14
- # If reloading is enabled, we need to put this constant for unloading
15
- # regardless of what cdef? says. In Ruby < 3.1 the internal state is not
16
- # fully cleared. Module#constants still includes it, and you need to
17
- # remove_const. See https://github.com/ruby/ruby/pull/4715.
18
- to_unload[cpath] = [file, cref] if reloading_enabled?
19
14
  Zeitwerk::Registry.unregister_autoload(file)
20
15
 
21
16
  if cdef?(*cref)
22
17
  log("constant #{cpath} loaded from file #{file}") if logger
18
+ to_unload[cpath] = [file, cref] if reloading_enabled?
23
19
  run_on_load_callbacks(cpath, cget(*cref), file) unless on_load_callbacks.empty?
24
20
  else
25
- raise Zeitwerk::NameError.new("expected file #{file} to define constant #{cpath}, but didn't", cref.last)
21
+ msg = "expected file #{file} to define constant #{cpath}, but didn't"
22
+ log(msg) if logger
23
+ crem(*cref)
24
+ to_unload[cpath] = [file, cref] if reloading_enabled?
25
+ raise Zeitwerk::NameError.new(msg, cref.last)
26
26
  end
27
27
  end
28
28
 
@@ -149,14 +149,24 @@ module Zeitwerk::Loader::Config
149
149
  # instead. Keys are the absolute paths of the root directories as strings,
150
150
  # values are their corresponding namespaces, class or module objects.
151
151
  #
152
+ # If `ignored` is falsey (default), ignored root directories are filtered out.
153
+ #
152
154
  # These are read-only collections, please add to them with `push_dir`.
153
155
  #
154
156
  # @sig () -> Array[String] | Hash[String, Module]
155
- def dirs(namespaces: false)
157
+ def dirs(namespaces: false, ignored: false)
156
158
  if namespaces
157
- roots.clone
159
+ if ignored || ignored_paths.empty?
160
+ roots.clone
161
+ else
162
+ roots.reject { |root_dir, _namespace| ignored_path?(root_dir) }
163
+ end
158
164
  else
159
- roots.keys
165
+ if ignored || ignored_paths.empty?
166
+ roots.keys
167
+ else
168
+ roots.keys.reject { |root_dir| ignored_path?(root_dir) }
169
+ end
160
170
  end.freeze
161
171
  end
162
172
 
@@ -183,7 +183,7 @@ module Zeitwerk::Loader::EagerLoad
183
183
  end
184
184
 
185
185
  # In order to invoke this method, the caller has to ensure `child` is a
186
- # strict namespace descendendant of `root_namespace`.
186
+ # strict namespace descendant of `root_namespace`.
187
187
  #
188
188
  # @sig (Module, String, Module, Boolean) -> void
189
189
  private def eager_load_child_namespace(child, child_name, root_dir, root_namespace)
@@ -208,7 +208,7 @@ module Zeitwerk::Loader::EagerLoad
208
208
  next unless dir?(abspath)
209
209
 
210
210
  if collapse?(abspath)
211
- current_dirs << abspath
211
+ dirs << abspath
212
212
  elsif segment == inflector.camelize(basename, abspath)
213
213
  next_dirs << abspath
214
214
  end
@@ -134,4 +134,10 @@ module Zeitwerk::Loader::Helpers
134
134
  private def cget(parent, cname)
135
135
  parent.const_get(cname, false)
136
136
  end
137
+
138
+ # @raise [NameError]
139
+ # @sig (Module, Symbol) -> Object
140
+ private def crem(parent, cname)
141
+ parent.__send__(:remove_const, cname)
142
+ end
137
143
  end
@@ -9,6 +9,8 @@ module Zeitwerk
9
9
  require_relative "loader/config"
10
10
  require_relative "loader/eager_load"
11
11
 
12
+ extend Internal
13
+
12
14
  include RealModName
13
15
  include Callbacks
14
16
  include Helpers
@@ -26,9 +28,9 @@ module Zeitwerk
26
28
  # "/Users/fxn/blog/app/models/hotel/pricing.rb" => [Hotel, :Pricing]
27
29
  # ...
28
30
  #
29
- # @private
30
31
  # @sig Hash[String, [Module, Symbol]]
31
32
  attr_reader :autoloads
33
+ internal :autoloads
32
34
 
33
35
  # We keep track of autoloaded directories to remove them from the registry
34
36
  # at the end of eager loading.
@@ -36,9 +38,9 @@ module Zeitwerk
36
38
  # Files are removed as they are autoloaded, but directories need to wait due
37
39
  # to concurrency (see why in Zeitwerk::Loader::Callbacks#on_dir_autoloaded).
38
40
  #
39
- # @private
40
41
  # @sig Array[String]
41
42
  attr_reader :autoloaded_dirs
43
+ internal :autoloaded_dirs
42
44
 
43
45
  # Stores metadata needed for unloading. Its entries look like this:
44
46
  #
@@ -52,9 +54,9 @@ module Zeitwerk
52
54
  # If reloading is enabled, this hash is filled as constants are autoloaded
53
55
  # or eager loaded. Otherwise, the collection remains empty.
54
56
  #
55
- # @private
56
57
  # @sig Hash[String, [String, [Module, Symbol]]]
57
58
  attr_reader :to_unload
59
+ internal :to_unload
58
60
 
59
61
  # Maps namespace constant paths to their respective directories.
60
62
  #
@@ -70,9 +72,9 @@ module Zeitwerk
70
72
  # and that its children are spread over those directories. We'll visit them
71
73
  # to set up the corresponding autoloads.
72
74
  #
73
- # @private
74
75
  # @sig Hash[String, Array[String]]
75
76
  attr_reader :namespace_dirs
77
+ internal :namespace_dirs
76
78
 
77
79
  # A shadowed file is a file managed by this loader that is ignored when
78
80
  # setting autoloads because its matching constant is already taken.
@@ -81,17 +83,17 @@ module Zeitwerk
81
83
  # has only scanned the top-level, `shadowed_files` does not have shadowed
82
84
  # files that may exist deep in the project tree yet.
83
85
  #
84
- # @private
85
86
  # @sig Set[String]
86
87
  attr_reader :shadowed_files
88
+ internal :shadowed_files
87
89
 
88
- # @private
89
90
  # @sig Mutex
90
91
  attr_reader :mutex
92
+ private :mutex
91
93
 
92
- # @private
93
94
  # @sig Mutex
94
95
  attr_reader :mutex2
96
+ private :mutex2
95
97
 
96
98
  def initialize
97
99
  super
@@ -134,7 +136,7 @@ module Zeitwerk
134
136
  # unload them.
135
137
  #
136
138
  # This method is public but undocumented. Main interface is `reload`, which
137
- # means `unload` + `setup`. This one is avaiable to be used together with
139
+ # means `unload` + `setup`. This one is available to be used together with
138
140
  # `unregister`, which is undocumented too.
139
141
  #
140
142
  # @sig () -> void
@@ -254,9 +256,8 @@ module Zeitwerk
254
256
  # The return value of this predicate is only meaningful if the loader has
255
257
  # scanned the file. This is the case in the spots where we use it.
256
258
  #
257
- # @private
258
259
  # @sig (String) -> Boolean
259
- def shadowed_file?(file)
260
+ internal def shadowed_file?(file)
260
261
  shadowed_files.member?(file)
261
262
  end
262
263
 
@@ -323,10 +324,8 @@ module Zeitwerk
323
324
  end
324
325
  end
325
326
 
326
- private # -------------------------------------------------------------------------------------
327
-
328
327
  # @sig (String, Module) -> void
329
- def set_autoloads_in_dir(dir, parent)
328
+ private def set_autoloads_in_dir(dir, parent)
330
329
  ls(dir) do |basename, abspath|
331
330
  begin
332
331
  if ruby?(basename)
@@ -361,13 +360,22 @@ module Zeitwerk
361
360
  end
362
361
 
363
362
  # @sig (Module, Symbol, String) -> void
364
- def autoload_subdir(parent, cname, subdir)
363
+ private def autoload_subdir(parent, cname, subdir)
365
364
  if autoload_path = autoload_path_set_by_me_for?(parent, cname)
366
365
  cpath = cpath(parent, cname)
367
- register_explicit_namespace(cpath) if ruby?(autoload_path)
368
- # We do not need to issue another autoload, the existing one is enough
369
- # no matter if it is for a file or a directory. Just remember the
370
- # subdirectory has to be visited if the namespace is used.
366
+ if ruby?(autoload_path)
367
+ # Scanning visited a Ruby file first, and now a directory for the same
368
+ # constant has been found. This means we are dealing with an explicit
369
+ # namespace whose definition was seen first.
370
+ #
371
+ # Registering is idempotent, and we have to keep the autoload pointing
372
+ # to the file. This may run again if more directories are found later
373
+ # on, no big deal.
374
+ register_explicit_namespace(cpath)
375
+ end
376
+ # If the existing autoload points to a file, it has to be preserved, if
377
+ # not, it is fine as it is. In either case, we do not need to override.
378
+ # Just remember the subdirectory conforms this namespace.
371
379
  namespace_dirs[cpath] << subdir
372
380
  elsif !cdef?(parent, cname)
373
381
  # First time we find this namespace, set an autoload for it.
@@ -382,7 +390,7 @@ module Zeitwerk
382
390
  end
383
391
 
384
392
  # @sig (Module, Symbol, String) -> void
385
- def autoload_file(parent, cname, file)
393
+ private def autoload_file(parent, cname, file)
386
394
  if autoload_path = strict_autoload_path(parent, cname) || Registry.inception?(cpath(parent, cname))
387
395
  # First autoload for a Ruby file wins, just ignore subsequent ones.
388
396
  if ruby?(autoload_path)
@@ -408,7 +416,7 @@ module Zeitwerk
408
416
  # the file where we've found the namespace is explicitly defined.
409
417
  #
410
418
  # @sig (dir: String, file: String, parent: Module, cname: Symbol) -> void
411
- def promote_namespace_from_implicit_to_explicit(dir:, file:, parent:, cname:)
419
+ private def promote_namespace_from_implicit_to_explicit(dir:, file:, parent:, cname:)
412
420
  autoloads.delete(dir)
413
421
  Registry.unregister_autoload(dir)
414
422
 
@@ -419,7 +427,7 @@ module Zeitwerk
419
427
  end
420
428
 
421
429
  # @sig (Module, Symbol, String) -> void
422
- def set_autoload(parent, cname, abspath)
430
+ private def set_autoload(parent, cname, abspath)
423
431
  parent.autoload(cname, abspath)
424
432
 
425
433
  if logger
@@ -440,7 +448,7 @@ module Zeitwerk
440
448
  end
441
449
 
442
450
  # @sig (Module, Symbol) -> String?
443
- def autoload_path_set_by_me_for?(parent, cname)
451
+ private def autoload_path_set_by_me_for?(parent, cname)
444
452
  if autoload_path = strict_autoload_path(parent, cname)
445
453
  autoload_path if autoloads.key?(autoload_path)
446
454
  else
@@ -449,12 +457,12 @@ module Zeitwerk
449
457
  end
450
458
 
451
459
  # @sig (String) -> void
452
- def register_explicit_namespace(cpath)
460
+ private def register_explicit_namespace(cpath)
453
461
  ExplicitNamespace.__register(cpath, self)
454
462
  end
455
463
 
456
464
  # @sig (String) -> void
457
- def raise_if_conflicting_directory(dir)
465
+ private def raise_if_conflicting_directory(dir)
458
466
  MUTEX.synchronize do
459
467
  dir_slash = dir + "/"
460
468
 
@@ -479,23 +487,23 @@ module Zeitwerk
479
487
  end
480
488
 
481
489
  # @sig (String, Object, String) -> void
482
- def run_on_unload_callbacks(cpath, value, abspath)
490
+ private def run_on_unload_callbacks(cpath, value, abspath)
483
491
  # Order matters. If present, run the most specific one.
484
492
  on_unload_callbacks[cpath]&.each { |c| c.call(value, abspath) }
485
493
  on_unload_callbacks[:ANY]&.each { |c| c.call(cpath, value, abspath) }
486
494
  end
487
495
 
488
496
  # @sig (Module, Symbol) -> void
489
- def unload_autoload(parent, cname)
490
- parent.__send__(:remove_const, cname)
497
+ private def unload_autoload(parent, cname)
498
+ crem(parent, cname)
491
499
  log("autoload for #{cpath(parent, cname)} removed") if logger
492
500
  end
493
501
 
494
502
  # @sig (Module, Symbol) -> void
495
- def unload_cref(parent, cname)
503
+ private def unload_cref(parent, cname)
496
504
  # Let's optimistically remove_const. The way we use it, this is going to
497
505
  # succeed always if all is good.
498
- parent.__send__(:remove_const, cname)
506
+ crem(parent, cname)
499
507
  rescue ::NameError
500
508
  # There are a few edge scenarios in which this may happen. If the constant
501
509
  # is gone, that is OK, anyway.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.6.5"
4
+ VERSION = "2.6.7"
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.5
4
+ version: 2.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Noria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-05 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.3.3
64
+ rubygems_version: 3.4.3
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Efficient and thread-safe constant autoloader