zeitwerk 2.3.1 → 2.5.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +213 -47
- data/lib/zeitwerk.rb +2 -0
- data/lib/zeitwerk/autoloads.rb +69 -0
- data/lib/zeitwerk/explicit_namespace.rb +17 -10
- data/lib/zeitwerk/gem_inflector.rb +2 -4
- data/lib/zeitwerk/inflector.rb +4 -7
- data/lib/zeitwerk/kernel.rb +7 -6
- data/lib/zeitwerk/loader.rb +112 -453
- data/lib/zeitwerk/loader/callbacks.rb +28 -12
- data/lib/zeitwerk/loader/config.rb +308 -0
- data/lib/zeitwerk/loader/helpers.rb +95 -0
- data/lib/zeitwerk/real_mod_name.rb +1 -2
- data/lib/zeitwerk/registry.rb +19 -30
- data/lib/zeitwerk/version.rb +1 -1
- metadata +12 -9
@@ -7,8 +7,7 @@ module Zeitwerk::RealModName
|
|
7
7
|
#
|
8
8
|
# The name method can be overridden, hence the indirection in this method.
|
9
9
|
#
|
10
|
-
# @
|
11
|
-
# @return [String, nil]
|
10
|
+
# @sig (Module) -> String?
|
12
11
|
if UnboundMethod.method_defined?(:bind_call)
|
13
12
|
def real_mod_name(mod)
|
14
13
|
UNBOUND_METHOD_MODULE_NAME.bind_call(mod)
|
data/lib/zeitwerk/registry.rb
CHANGED
@@ -7,23 +7,23 @@ module Zeitwerk
|
|
7
7
|
# them from being garbage collected.
|
8
8
|
#
|
9
9
|
# @private
|
10
|
-
# @
|
10
|
+
# @sig Array[Zeitwerk::Loader]
|
11
11
|
attr_reader :loaders
|
12
12
|
|
13
13
|
# Registers loaders created with `for_gem` to make the method idempotent
|
14
14
|
# in case of reload.
|
15
15
|
#
|
16
16
|
# @private
|
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.
|
24
24
|
#
|
25
25
|
# @private
|
26
|
-
# @
|
26
|
+
# @sig Hash[String, Zeitwerk::Loader]
|
27
27
|
attr_reader :autoloads
|
28
28
|
|
29
29
|
# This hash table addresses an edge case in which an autoload is ignored.
|
@@ -62,14 +62,13 @@ module Zeitwerk
|
|
62
62
|
# end
|
63
63
|
#
|
64
64
|
# @private
|
65
|
-
# @
|
65
|
+
# @sig Hash[String, [String, Zeitwerk::Loader]]
|
66
66
|
attr_reader :inceptions
|
67
67
|
|
68
68
|
# Registers a loader.
|
69
69
|
#
|
70
70
|
# @private
|
71
|
-
# @
|
72
|
-
# @return [void]
|
71
|
+
# @sig (Zeitwerk::Loader) -> void
|
73
72
|
def register_loader(loader)
|
74
73
|
loaders << loader
|
75
74
|
end
|
@@ -78,8 +77,7 @@ module Zeitwerk
|
|
78
77
|
# file. That is how Zeitwerk::Loader.for_gem is idempotent.
|
79
78
|
#
|
80
79
|
# @private
|
81
|
-
# @
|
82
|
-
# @return [Zeitwerk::Loader]
|
80
|
+
# @sig (String) -> Zeitwerk::Loader
|
83
81
|
def loader_for_gem(root_file)
|
84
82
|
loaders_managing_gems[root_file] ||= begin
|
85
83
|
Loader.new.tap do |loader|
|
@@ -91,32 +89,25 @@ module Zeitwerk
|
|
91
89
|
end
|
92
90
|
|
93
91
|
# @private
|
94
|
-
# @
|
95
|
-
|
96
|
-
|
97
|
-
def register_autoload(loader, realpath)
|
98
|
-
autoloads[realpath] = loader
|
92
|
+
# @sig (Zeitwerk::Loader, String) -> String
|
93
|
+
def register_autoload(loader, abspath)
|
94
|
+
autoloads[abspath] = loader
|
99
95
|
end
|
100
96
|
|
101
97
|
# @private
|
102
|
-
# @
|
103
|
-
|
104
|
-
|
105
|
-
autoloads.delete(realpath)
|
98
|
+
# @sig (String) -> void
|
99
|
+
def unregister_autoload(abspath)
|
100
|
+
autoloads.delete(abspath)
|
106
101
|
end
|
107
102
|
|
108
103
|
# @private
|
109
|
-
# @
|
110
|
-
|
111
|
-
|
112
|
-
# @return [void]
|
113
|
-
def register_inception(cpath, realpath, loader)
|
114
|
-
inceptions[cpath] = [realpath, loader]
|
104
|
+
# @sig (String, String, Zeitwerk::Loader) -> void
|
105
|
+
def register_inception(cpath, abspath, loader)
|
106
|
+
inceptions[cpath] = [abspath, loader]
|
115
107
|
end
|
116
108
|
|
117
109
|
# @private
|
118
|
-
# @
|
119
|
-
# @return [String, nil]
|
110
|
+
# @sig (String) -> String?
|
120
111
|
def inception?(cpath)
|
121
112
|
if pair = inceptions[cpath]
|
122
113
|
pair.first
|
@@ -124,15 +115,13 @@ module Zeitwerk
|
|
124
115
|
end
|
125
116
|
|
126
117
|
# @private
|
127
|
-
# @
|
128
|
-
# @return [Zeitwerk::Loader, nil]
|
118
|
+
# @sig (String) -> Zeitwerk::Loader?
|
129
119
|
def loader_for(path)
|
130
120
|
autoloads[path]
|
131
121
|
end
|
132
122
|
|
133
123
|
# @private
|
134
|
-
# @
|
135
|
-
# @return [void]
|
124
|
+
# @sig (Zeitwerk::Loader) -> void
|
136
125
|
def on_unload(loader)
|
137
126
|
autoloads.delete_if { |_path, object| object == loader }
|
138
127
|
inceptions.delete_if { |_cpath, (_path, object)| object == loader }
|
data/lib/zeitwerk/version.rb
CHANGED
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.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Noria
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-08-03 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
|
@@ -41,7 +44,7 @@ metadata:
|
|
41
44
|
changelog_uri: https://github.com/fxn/zeitwerk/blob/master/CHANGELOG.md
|
42
45
|
source_code_uri: https://github.com/fxn/zeitwerk
|
43
46
|
bug_tracker_uri: https://github.com/fxn/zeitwerk/issues
|
44
|
-
post_install_message:
|
47
|
+
post_install_message:
|
45
48
|
rdoc_options: []
|
46
49
|
require_paths:
|
47
50
|
- lib
|
@@ -49,15 +52,15 @@ 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.1.
|
60
|
-
signing_key:
|
62
|
+
rubygems_version: 3.1.6
|
63
|
+
signing_key:
|
61
64
|
specification_version: 4
|
62
65
|
summary: Efficient and thread-safe constant autoloader
|
63
66
|
test_files: []
|