zeitwerk 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e458722eb922aa69f1c49c077b9cfa0bb8c0fa14d7a12f295b7375e5f31d6d33
4
- data.tar.gz: 414f3bbe461b6081c39eff4640fda5eae0ea7d2e1649a981f84759ba6db538a7
3
+ metadata.gz: 0ff8931860945782c104aae3e03599df5c84dfdfd05aa422b3b467f227fabb23
4
+ data.tar.gz: aca07442b309c1d842ebcc9351c4c489c601331832308aee6f8f5bb49a43e4bc
5
5
  SHA512:
6
- metadata.gz: fc0a61c385d372cdba449e80473d793133e71fc502cbda1f504d64759f6ff9e1ea65ebdcead21c472b89c84951915d687de2a3e71bff8307b91e2e4bd29339d5
7
- data.tar.gz: 5b851f501b91740176047eb1fca04c3b5de04c482b055dc7605a15cbf571b719e4bb9e11bc939521411e1965ef07e539a023dc83b40eb059234b86fe41bf73d5
6
+ metadata.gz: e42fb0efc142bae7da85f21d3d8650c5ef8a24f5f07b3b673ca6f4e74b952c90d7d935f4d2fd1c8efa217d0e19476472435df6ee7547f6c76f190796fc87c202
7
+ data.tar.gz: 1ced31f03716433f32e534952c2811bee84885c6e376c5e5e227ce695bd891154fa8464747b4e0844a74dd1e9a2d196dd3cace12835312e340ae424834b58433
@@ -96,7 +96,7 @@ module Zeitwerk
96
96
  #
97
97
  # "Admin::Role" => [".../admin/role.rb", [Admin, :Role]]
98
98
  #
99
- # The constant path as key helps implementing to_unload? The real file name
99
+ # The cpath as key helps implementing unloadable_cpath? The real file name
100
100
  # is stored in order to be able to delete it from $LOADED_FEATURES, and the
101
101
  # pair [Module, Symbol] is used to remove_const the constant from the class
102
102
  # or module object.
@@ -262,7 +262,7 @@ module Zeitwerk
262
262
  break if @setup
263
263
 
264
264
  expand_ignored_glob_patterns
265
- non_ignored_root_dirs.each { |root_dir| set_autoloads_in_dir(root_dir, Object) }
265
+ actual_root_dirs.each { |root_dir| set_autoloads_in_dir(root_dir, Object) }
266
266
  do_preload
267
267
 
268
268
  @setup = true
@@ -292,9 +292,9 @@ module Zeitwerk
292
292
  if parent.autoload?(cname)
293
293
  unload_autoload(parent, cname)
294
294
  else
295
- # Could happen if loaded with require_relative. require_relative is
296
- # not supported, and the cpath would escape `to_unload?`. This is
297
- # just defensive code to clean things up as much as we are able to.
295
+ # Could happen if loaded with require_relative. That is unsupported,
296
+ # and the constant path would escape unloadable_cpath? This is just
297
+ # defensive code to clean things up as much as we are able to.
298
298
  unload_cref(parent, cname) if cdef?(parent, cname)
299
299
  unloaded_files.add(realpath) if ruby?(realpath)
300
300
  end
@@ -360,7 +360,7 @@ module Zeitwerk
360
360
  mutex.synchronize do
361
361
  break if @eager_loaded
362
362
 
363
- queue = non_ignored_root_dirs.reject { |dir| eager_load_exclusions.member?(dir) }
363
+ queue = actual_root_dirs.reject { |dir| eager_load_exclusions.member?(dir) }
364
364
  while dir = queue.shift
365
365
  each_abspath(dir) do |abspath|
366
366
  next if eager_load_exclusions.member?(abspath)
@@ -398,10 +398,18 @@ module Zeitwerk
398
398
  #
399
399
  # @param cpath [String]
400
400
  # @return [Boolean]
401
- def to_unload?(cpath)
401
+ def unloadable_cpath?(cpath)
402
402
  to_unload.key?(cpath)
403
403
  end
404
404
 
405
+ # Returns an array with the constant paths that would be unloaded on reload.
406
+ # This predicate returns an empty array if reloading is disabled.
407
+ #
408
+ # @return [<String>]
409
+ def unloadable_cpaths
410
+ to_unload.keys.freeze
411
+ end
412
+
405
413
  # --- Class methods ---------------------------------------------------------------------------
406
414
 
407
415
  class << self
@@ -450,8 +458,10 @@ module Zeitwerk
450
458
  private # -------------------------------------------------------------------------------------
451
459
 
452
460
  # @return [<String>]
453
- def non_ignored_root_dirs
454
- root_dirs.keys.delete_if { |root_dir| ignored_paths.member?(root_dir) }
461
+ def actual_root_dirs
462
+ root_dirs.keys.delete_if do |root_dir|
463
+ !dir?(root_dir) || ignored_paths.member?(root_dir)
464
+ end
455
465
  end
456
466
 
457
467
  # @param dir [String]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.1.3"
4
+ VERSION = "2.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeitwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Noria