zeitwerk 2.5.1 → 2.5.4

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: 1f424f7f7538a469affa93fbe0c24533d146eb8dfe7289f3c5167b36abd0e362
4
- data.tar.gz: 8aa11ee61f57a965e3fbb705713f6a4dcf0e3586dc8a3e90f35801b8e8ff9e12
3
+ metadata.gz: 3640f4751b86923c0dc81be1aed0580b1e2bdef59c6d3cc06c0c736d03b78c3b
4
+ data.tar.gz: 262a7697cfca8fa8d9630687ba8439dd9df404c052b71e5b91fb498c4114e5db
5
5
  SHA512:
6
- metadata.gz: 70022bbaa975835042e6550a3e1f8ca8e09e7e1f764d29c659adc9d6c727765fea276da4425ae43e7f4baaaaae6f167d9f4c567e63c0d322ac553603f2d6063b
7
- data.tar.gz: 7144f057043a326be20b866b2a23dc3c2b5cd3274a084a73770e6b643f65e308ba2eacfbf87701092ee20d440e256d0afe37066933d396cb332d28e5108775a7
6
+ metadata.gz: 7decde169af7a300ae8962339a8886cede3cfdd75ade4d7428c39a53f3dad96c194b7e938938811dce8208f70dfcf2cc29735c03384eaa776dbc2985fea87325
7
+ data.tar.gz: 99c16812c1ad437860029642af2d1c1ffc00962369aa1f6dc770b1f64d102b09f046c3ad3ae2dc44d50479314a14b8c9ddb2d446a619407ca05178aff43890de
data/README.md CHANGED
@@ -50,8 +50,8 @@
50
50
  - [Rules of thumb](#rules-of-thumb)
51
51
  - [Debuggers](#debuggers)
52
52
  - [debug.rb](#debugrb)
53
- - [Break](#break)
54
53
  - [Byebug](#byebug)
54
+ - [Break](#break)
55
55
  - [Pronunciation](#pronunciation)
56
56
  - [Supported Ruby versions](#supported-ruby-versions)
57
57
  - [Testing](#testing)
@@ -437,7 +437,7 @@ However, that can be overridden with `force`:
437
437
  loader.eager_load(force: true) # database adapters are eager loaded
438
438
  ```
439
439
 
440
- Which may be handy if the project eager loads in the test suite to [ensure project layour compliance](#testing-compliance).
440
+ Which may be handy if the project eager loads in the test suite to [ensure project layout compliance](#testing-compliance).
441
441
 
442
442
  The `force` flag does not affect ignored files and directories, those are still ignored.
443
443
 
@@ -810,7 +810,9 @@ Kernel.module_eval do
810
810
  end
811
811
  ```
812
812
 
813
- That file does not define a constant path after the path name and you need to tell Zeitwerk:
813
+ `Kernel` is already defined by Ruby so the module cannot be autoloaded. Also, that file does not define a constant path after the path name. Therefore, Zeitwerk should not process it at all.
814
+
815
+ The extension can still coexist with the rest of the project, you only need to tell Zeitwerk to ignore it:
814
816
 
815
817
  ```ruby
816
818
  kernel_ext = "#{__dir__}/my_gem/core_ext/kernel.rb"
@@ -826,6 +828,14 @@ loader.ignore(core_ext)
826
828
  loader.setup
827
829
  ```
828
830
 
831
+ Now, that file has to be loaded manually with `require` or `require_relative`:
832
+
833
+ ```ruby
834
+ require_relative "my_gem/core_ext/kernel"
835
+ ```
836
+
837
+ and you can do that anytime, before configuring the loader, or after configuring the loader, does not matter.
838
+
829
839
  <a id="markdown-use-case-the-adapter-pattern" name="use-case-the-adapter-pattern"></a>
830
840
  #### Use case: The adapter pattern
831
841
 
@@ -973,17 +983,19 @@ With that, when Zeitwerk scans the file system and reaches the gem directories `
973
983
  <a id="markdown-debugrb" name="debugrb"></a>
974
984
  #### debug.rb
975
985
 
976
- The new [debug.rb](https://github.com/ruby/debug) gem and Zeitwerk seem to be compatible, as far as I can tell. This is the new debugger that is going to ship with Ruby 3.1.
986
+ 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.
977
987
 
978
- <a id="markdown-break" name="break"></a>
979
- #### Break
980
-
981
- Zeitwerk works fine with [@gsamokovarov](https://github.com/gsamokovarov)'s [Break](https://github.com/gsamokovarov/break) debugger.
988
+ 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).
982
989
 
983
990
  <a id="markdown-byebug" name="byebug"></a>
984
991
  #### Byebug
985
992
 
986
- Zeitwerk and [Byebug](https://github.com/deivid-rodriguez/byebug) are incompatible, classes or modules that belong to [explicit namespaces](#explicit-namespaces) are not autoloaded inside a Byebug session. See [this issue](https://github.com/deivid-rodriguez/byebug/issues/564#issuecomment-499413606) for further details.
993
+ Zeitwerk and [Byebug](https://github.com/deivid-rodriguez/byebug) have a similar edge incompatibility.
994
+
995
+ <a id="markdown-break" name="break"></a>
996
+ #### Break
997
+
998
+ Zeitwerk works fine with [@gsamokovarov](https://github.com/gsamokovarov)'s [Break](https://github.com/gsamokovarov/break) debugger.
987
999
 
988
1000
  <a id="markdown-pronunciation" name="pronunciation"></a>
989
1001
  ## Pronunciation
@@ -3,11 +3,11 @@
3
3
  module Kernel
4
4
  module_function
5
5
 
6
- # We are going to decorate Kernel#require with two goals.
6
+ # Zeitwerk's main idea is to define autoloads for project constants, and then
7
+ # intercept them when triggered in this thin `Kernel#require` wrapper.
7
8
  #
8
- # First, by intercepting Kernel#require calls, we are able to autovivify
9
- # modules on required directories, and also do internal housekeeping when
10
- # managed files are loaded.
9
+ # That allows us to complete the circle, invoke callbacks, autovivify modules,
10
+ # define autoloads for just autoloaded namespaces, update internal state, etc.
11
11
  #
12
12
  # On the other hand, if you publish a new version of a gem that is now managed
13
13
  # by Zeitwerk, client code can reference directly your classes and modules and
@@ -17,29 +17,29 @@ module Kernel
17
17
  #
18
18
  # We cannot decorate with prepend + super because Kernel has already been
19
19
  # included in Object, and changes in ancestors don't get propagated into
20
- # already existing ancestor chains.
20
+ # already existing ancestor chains on Ruby < 3.0.
21
21
  alias_method :zeitwerk_original_require, :require
22
22
 
23
23
  # @sig (String) -> true | false
24
24
  def require(path)
25
25
  if loader = Zeitwerk::Registry.loader_for(path)
26
26
  if path.end_with?(".rb")
27
- zeitwerk_original_require(path).tap do |required|
28
- loader.on_file_autoloaded(path) if required
29
- end
27
+ required = zeitwerk_original_require(path)
28
+ loader.on_file_autoloaded(path) if required
29
+ required
30
30
  else
31
31
  loader.on_dir_autoloaded(path)
32
32
  true
33
33
  end
34
34
  else
35
- zeitwerk_original_require(path).tap do |required|
36
- if required
37
- abspath = $LOADED_FEATURES.last
38
- if loader = Zeitwerk::Registry.loader_for(abspath)
39
- loader.on_file_autoloaded(abspath)
40
- end
35
+ required = zeitwerk_original_require(path)
36
+ if required
37
+ abspath = $LOADED_FEATURES.last
38
+ if loader = Zeitwerk::Registry.loader_for(abspath)
39
+ loader.on_file_autoloaded(abspath)
41
40
  end
42
41
  end
42
+ required
43
43
  end
44
44
  end
45
45
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "set"
4
- require "securerandom"
5
4
 
6
5
  module Zeitwerk
7
6
  class Loader
@@ -145,7 +144,13 @@ module Zeitwerk
145
144
  end
146
145
 
147
146
  to_unload.each do |cpath, (abspath, (parent, cname))|
148
- unless on_unload_callbacks.empty?
147
+ # We have to check cdef? in this condition. Reason is, constants whose
148
+ # file does not define them have to be kept in to_unload as explained
149
+ # in the implementation of on_file_autoloaded.
150
+ #
151
+ # If the constant is not defined, on_unload should not be triggered
152
+ # for it.
153
+ if !on_unload_callbacks.empty? && cdef?(parent, cname)
149
154
  value = parent.const_get(cname)
150
155
  run_on_unload_callbacks(cpath, value, abspath)
151
156
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.5.1"
4
+ VERSION = "2.5.4"
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.1
4
+ version: 2.5.4
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-10-20 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.2.22
61
+ rubygems_version: 3.3.3
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Efficient and thread-safe constant autoloader