zeitwerk 2.5.0.beta5 → 2.5.0.beta6

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: a57a618cc6c371488c6b2a1360b3bfb37b4914e7c44addd688dd9ff6d245f92b
4
- data.tar.gz: 927300a0bec3a2941e79e3065068cb3359ced9a368a23204e31eb76c1de347bc
3
+ metadata.gz: 74d74bec1f4963cc5d04f037e14723408ae5d1f8c4df16f31f2901402e3230ed
4
+ data.tar.gz: 3ebd7f860583cc7a560360b2e766193dc0c74c5cd902c7cb632a614e32dc68e7
5
5
  SHA512:
6
- metadata.gz: 2c26a751d80bcf719e2705c30c24e78300141b8cfe4a57e3bed2a9bf26e80534755a0fe067b6f32e6c1f4e7bbaf7693232640a76ff710e868c07f11128e9da6d
7
- data.tar.gz: 270a9053e7ecccf58366272d6e60d2d3967d80f3d9777a0825700efcacf95e468a31c29924436df4231a53a971d31b0b4157d9f8bb8b82a91bd6fb6b2fdfb592
6
+ metadata.gz: f0bec92696285efb5ad1f76094b71a4de5a38a0665b493737c945623042b4d744be2c58f4006ed5c8c4abe0ccb70854c94ba63c3b7eeef1a5ae47086a956668d
7
+ data.tar.gz: a1392b3b73dcd85769f793aeca9a9d10cb50c70259d88761574c1e62e201b24f32d7122eda587af6017dea93fca27ce9463e5f0dae7b98523d3edba2c13802eb
@@ -11,16 +11,19 @@ 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.
14
18
  to_unload[cpath] = [file, cref] if reloading_enabled?
15
19
  Zeitwerk::Registry.unregister_autoload(file)
16
20
 
17
- if logger && cdef?(*cref)
18
- log("constant #{cpath} loaded from file #{file}")
19
- elsif !cdef?(*cref)
21
+ if cdef?(*cref)
22
+ log("constant #{cpath} loaded from file #{file}") if logger
23
+ run_on_load_callbacks(cpath, cget(*cref), file) unless on_load_callbacks.empty?
24
+ else
20
25
  raise Zeitwerk::NameError.new("expected file #{file} to define constant #{cpath}, but didn't", cref.last)
21
26
  end
22
-
23
- run_on_load_callbacks(cpath, cget(*cref), file) unless on_load_callbacks.empty?
24
27
  end
25
28
 
26
29
  # Invoked from our decorated Kernel#require when a managed directory is
@@ -145,7 +145,7 @@ module Zeitwerk
145
145
  # Could happen if loaded with require_relative. That is unsupported,
146
146
  # and the constant path would escape unloadable_cpath? This is just
147
147
  # defensive code to clean things up as much as we are able to.
148
- unload_cref(parent, cname) if cdef?(parent, cname)
148
+ unload_cref(parent, cname)
149
149
  unloaded_files.add(abspath) if ruby?(abspath)
150
150
  end
151
151
  end
@@ -156,7 +156,7 @@ module Zeitwerk
156
156
  run_on_unload_callbacks(cpath, value, abspath)
157
157
  end
158
158
 
159
- unload_cref(parent, cname) if cdef?(parent, cname)
159
+ unload_cref(parent, cname)
160
160
  unloaded_files.add(abspath) if ruby?(abspath)
161
161
  end
162
162
 
@@ -494,7 +494,13 @@ module Zeitwerk
494
494
 
495
495
  # @sig (Module, Symbol) -> void
496
496
  def unload_cref(parent, cname)
497
+ # Let's optimistically remove_const. The way we use it, this is going to
498
+ # succeed always if all is good.
497
499
  parent.__send__(:remove_const, cname)
500
+ rescue ::NameError
501
+ # There are a few edge scenarios in which this may happen. If the constant
502
+ # is gone, that is OK, anyway.
503
+ else
498
504
  log("#{cpath(parent, cname)} unloaded") if logger
499
505
  end
500
506
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.5.0.beta5"
4
+ VERSION = "2.5.0.beta6"
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.5.0.beta5
4
+ version: 2.5.0.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Noria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-29 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem