zeitwerk 2.4.1 → 2.5.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +221 -57
- data/lib/zeitwerk/autoloads.rb +69 -0
- data/lib/zeitwerk/explicit_namespace.rb +9 -3
- data/lib/zeitwerk/kernel.rb +6 -4
- data/lib/zeitwerk/loader/callbacks.rb +25 -6
- data/lib/zeitwerk/loader/config.rb +301 -0
- data/lib/zeitwerk/loader/helpers.rb +95 -0
- data/lib/zeitwerk/loader.rb +100 -394
- data/lib/zeitwerk/registry.rb +16 -7
- data/lib/zeitwerk/version.rb +1 -1
- data/lib/zeitwerk.rb +13 -0
- metadata +9 -6
data/lib/zeitwerk/registry.rb
CHANGED
@@ -17,7 +17,7 @@ module Zeitwerk
|
|
17
17
|
# @sig Hash[String, Zeitwerk::Loader]
|
18
18
|
attr_reader :loaders_managing_gems
|
19
19
|
|
20
|
-
# Maps
|
20
|
+
# Maps absolute paths to the loaders responsible for them.
|
21
21
|
#
|
22
22
|
# This information is used by our decorated `Kernel#require` to be able to
|
23
23
|
# invoke callbacks and autovivify modules.
|
@@ -73,6 +73,15 @@ module Zeitwerk
|
|
73
73
|
loaders << loader
|
74
74
|
end
|
75
75
|
|
76
|
+
# @private
|
77
|
+
# @sig (Zeitwerk::Loader) -> void
|
78
|
+
def unregister_loader(loader)
|
79
|
+
loaders.delete(loader)
|
80
|
+
loaders_managing_gems.delete_if { |_, l| l == loader }
|
81
|
+
autoloads.delete_if { |_, l| l == loader }
|
82
|
+
inceptions.delete_if { |_, (_, l)| l == loader }
|
83
|
+
end
|
84
|
+
|
76
85
|
# This method returns always a loader, the same instance for the same root
|
77
86
|
# file. That is how Zeitwerk::Loader.for_gem is idempotent.
|
78
87
|
#
|
@@ -90,20 +99,20 @@ module Zeitwerk
|
|
90
99
|
|
91
100
|
# @private
|
92
101
|
# @sig (Zeitwerk::Loader, String) -> String
|
93
|
-
def register_autoload(loader,
|
94
|
-
autoloads[
|
102
|
+
def register_autoload(loader, abspath)
|
103
|
+
autoloads[abspath] = loader
|
95
104
|
end
|
96
105
|
|
97
106
|
# @private
|
98
107
|
# @sig (String) -> void
|
99
|
-
def unregister_autoload(
|
100
|
-
autoloads.delete(
|
108
|
+
def unregister_autoload(abspath)
|
109
|
+
autoloads.delete(abspath)
|
101
110
|
end
|
102
111
|
|
103
112
|
# @private
|
104
113
|
# @sig (String, String, Zeitwerk::Loader) -> void
|
105
|
-
def register_inception(cpath,
|
106
|
-
inceptions[cpath] = [
|
114
|
+
def register_inception(cpath, abspath, loader)
|
115
|
+
inceptions[cpath] = [abspath, loader]
|
107
116
|
end
|
108
117
|
|
109
118
|
# @private
|
data/lib/zeitwerk/version.rb
CHANGED
data/lib/zeitwerk.rb
CHANGED
@@ -3,10 +3,23 @@
|
|
3
3
|
module Zeitwerk
|
4
4
|
require_relative "zeitwerk/real_mod_name"
|
5
5
|
require_relative "zeitwerk/loader"
|
6
|
+
require_relative "zeitwerk/autoloads"
|
6
7
|
require_relative "zeitwerk/registry"
|
7
8
|
require_relative "zeitwerk/explicit_namespace"
|
8
9
|
require_relative "zeitwerk/inflector"
|
9
10
|
require_relative "zeitwerk/gem_inflector"
|
10
11
|
require_relative "zeitwerk/kernel"
|
11
12
|
require_relative "zeitwerk/error"
|
13
|
+
require_relative "zeitwerk/version"
|
14
|
+
|
15
|
+
# This is a dangerous method.
|
16
|
+
#
|
17
|
+
# @experimental
|
18
|
+
# @sig () -> void
|
19
|
+
def self.with_loader
|
20
|
+
loader = Zeitwerk::Loader.new
|
21
|
+
yield loader
|
22
|
+
ensure
|
23
|
+
loader.unregister
|
24
|
+
end
|
12
25
|
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.
|
4
|
+
version: 2.5.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Noria
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Zeitwerk implements constant autoloading with Ruby semantics. Each gem
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- MIT-LICENSE
|
24
24
|
- README.md
|
25
25
|
- lib/zeitwerk.rb
|
26
|
+
- lib/zeitwerk/autoloads.rb
|
26
27
|
- lib/zeitwerk/error.rb
|
27
28
|
- lib/zeitwerk/explicit_namespace.rb
|
28
29
|
- lib/zeitwerk/gem_inflector.rb
|
@@ -30,6 +31,8 @@ files:
|
|
30
31
|
- lib/zeitwerk/kernel.rb
|
31
32
|
- lib/zeitwerk/loader.rb
|
32
33
|
- lib/zeitwerk/loader/callbacks.rb
|
34
|
+
- lib/zeitwerk/loader/config.rb
|
35
|
+
- lib/zeitwerk/loader/helpers.rb
|
33
36
|
- lib/zeitwerk/real_mod_name.rb
|
34
37
|
- lib/zeitwerk/registry.rb
|
35
38
|
- lib/zeitwerk/version.rb
|
@@ -49,14 +52,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
52
|
requirements:
|
50
53
|
- - ">="
|
51
54
|
- !ruby/object:Gem::Version
|
52
|
-
version: 2.
|
55
|
+
version: '2.5'
|
53
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
57
|
requirements:
|
55
|
-
- - "
|
58
|
+
- - ">"
|
56
59
|
- !ruby/object:Gem::Version
|
57
|
-
version:
|
60
|
+
version: 1.3.1
|
58
61
|
requirements: []
|
59
|
-
rubygems_version: 3.
|
62
|
+
rubygems_version: 3.2.22
|
60
63
|
signing_key:
|
61
64
|
specification_version: 4
|
62
65
|
summary: Efficient and thread-safe constant autoloader
|