zeitwerk 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zeitwerk/loader.rb +22 -18
- data/lib/zeitwerk/version.rb +1 -1
- data/lib/zeitwerk.rb +0 -1
- metadata +1 -2
- data/lib/zeitwerk/autoloads.rb +0 -71
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f424f7f7538a469affa93fbe0c24533d146eb8dfe7289f3c5167b36abd0e362
|
4
|
+
data.tar.gz: 8aa11ee61f57a965e3fbb705713f6a4dcf0e3586dc8a3e90f35801b8e8ff9e12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70022bbaa975835042e6550a3e1f8ca8e09e7e1f764d29c659adc9d6c727765fea276da4425ae43e7f4baaaaae6f167d9f4c567e63c0d322ac553603f2d6063b
|
7
|
+
data.tar.gz: 7144f057043a326be20b866b2a23dc3c2b5cd3274a084a73770e6b643f65e308ba2eacfbf87701092ee20d440e256d0afe37066933d396cb332d28e5108775a7
|
data/lib/zeitwerk/loader.rb
CHANGED
@@ -14,22 +14,16 @@ module Zeitwerk
|
|
14
14
|
include Helpers
|
15
15
|
include Config
|
16
16
|
|
17
|
-
#
|
18
|
-
# executed
|
17
|
+
# Maps absolute paths for which an autoload has been set ---and not
|
18
|
+
# executed--- to their corresponding parent class or module and constant
|
19
|
+
# name.
|
19
20
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# and invoke user callbacks. If reloading is enabled, remember cref and
|
24
|
-
# abspath for later unloading logic.
|
25
|
-
#
|
26
|
-
# 2. When unloading, remove autoloads that have not been executed.
|
27
|
-
#
|
28
|
-
# 3. Eager load with a recursive const_get, rather than a recursive require,
|
29
|
-
# for consistency with lazy loading.
|
21
|
+
# "/Users/fxn/blog/app/models/user.rb" => [Object, :User],
|
22
|
+
# "/Users/fxn/blog/app/models/hotel/pricing.rb" => [Hotel, :Pricing]
|
23
|
+
# ...
|
30
24
|
#
|
31
25
|
# @private
|
32
|
-
# @sig
|
26
|
+
# @sig Hash[String, [Module, Symbol]]
|
33
27
|
attr_reader :autoloads
|
34
28
|
|
35
29
|
# We keep track of autoloaded directories to remove them from the registry
|
@@ -87,7 +81,7 @@ module Zeitwerk
|
|
87
81
|
def initialize
|
88
82
|
super
|
89
83
|
|
90
|
-
@autoloads =
|
84
|
+
@autoloads = {}
|
91
85
|
@autoloaded_dirs = []
|
92
86
|
@to_unload = {}
|
93
87
|
@lazy_subdirs = Hash.new { |h, cpath| h[cpath] = [] }
|
@@ -138,7 +132,7 @@ module Zeitwerk
|
|
138
132
|
# is enough.
|
139
133
|
unloaded_files = Set.new
|
140
134
|
|
141
|
-
autoloads.each do |(parent, cname)
|
135
|
+
autoloads.each do |abspath, (parent, cname)|
|
142
136
|
if parent.autoload?(cname)
|
143
137
|
unload_autoload(parent, cname)
|
144
138
|
else
|
@@ -234,7 +228,7 @@ module Zeitwerk
|
|
234
228
|
next if honour_exclusions && excluded_from_eager_load?(abspath)
|
235
229
|
|
236
230
|
if ruby?(abspath)
|
237
|
-
if cref = autoloads
|
231
|
+
if cref = autoloads[abspath]
|
238
232
|
cget(*cref)
|
239
233
|
end
|
240
234
|
elsif dir?(abspath) && !root_dirs.key?(abspath)
|
@@ -376,7 +370,7 @@ module Zeitwerk
|
|
376
370
|
|
377
371
|
# @sig (Module, Symbol, String) -> void
|
378
372
|
def autoload_subdir(parent, cname, subdir)
|
379
|
-
if autoload_path =
|
373
|
+
if autoload_path = autoload_path_set_by_me_for?(parent, cname)
|
380
374
|
cpath = cpath(parent, cname)
|
381
375
|
register_explicit_namespace(cpath) if ruby?(autoload_path)
|
382
376
|
# We do not need to issue another autoload, the existing one is enough
|
@@ -432,7 +426,7 @@ module Zeitwerk
|
|
432
426
|
|
433
427
|
# @sig (Module, Symbol, String) -> void
|
434
428
|
def set_autoload(parent, cname, abspath)
|
435
|
-
|
429
|
+
parent.autoload(cname, abspath)
|
436
430
|
|
437
431
|
if logger
|
438
432
|
if ruby?(abspath)
|
@@ -442,6 +436,7 @@ module Zeitwerk
|
|
442
436
|
end
|
443
437
|
end
|
444
438
|
|
439
|
+
autoloads[abspath] = [parent, cname]
|
445
440
|
Registry.register_autoload(self, abspath)
|
446
441
|
|
447
442
|
# See why in the documentation of Zeitwerk::Registry.inceptions.
|
@@ -450,6 +445,15 @@ module Zeitwerk
|
|
450
445
|
end
|
451
446
|
end
|
452
447
|
|
448
|
+
# @sig (Module, Symbol) -> String?
|
449
|
+
def autoload_path_set_by_me_for?(parent, cname)
|
450
|
+
if autoload_path = strict_autoload_path(parent, cname)
|
451
|
+
autoload_path if autoloads.key?(autoload_path)
|
452
|
+
else
|
453
|
+
Registry.inception?(cpath(parent, cname))
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
453
457
|
# @sig (String) -> void
|
454
458
|
def register_explicit_namespace(cpath)
|
455
459
|
ExplicitNamespace.register(cpath, self)
|
data/lib/zeitwerk/version.rb
CHANGED
data/lib/zeitwerk.rb
CHANGED
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.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Noria
|
@@ -23,7 +23,6 @@ files:
|
|
23
23
|
- MIT-LICENSE
|
24
24
|
- README.md
|
25
25
|
- lib/zeitwerk.rb
|
26
|
-
- lib/zeitwerk/autoloads.rb
|
27
26
|
- lib/zeitwerk/error.rb
|
28
27
|
- lib/zeitwerk/explicit_namespace.rb
|
29
28
|
- lib/zeitwerk/gem_inflector.rb
|
data/lib/zeitwerk/autoloads.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Zeitwerk
|
4
|
-
# @private
|
5
|
-
class Autoloads
|
6
|
-
# Maps crefs for which an autoload has been defined to the corresponding
|
7
|
-
# absolute path.
|
8
|
-
#
|
9
|
-
# [Object, :User] => "/Users/fxn/blog/app/models/user.rb"
|
10
|
-
# [Object, :Hotel] => "/Users/fxn/blog/app/models/hotel"
|
11
|
-
# ...
|
12
|
-
#
|
13
|
-
# This colection is transient, callbacks delete its entries as autoloads get
|
14
|
-
# executed.
|
15
|
-
#
|
16
|
-
# @sig Hash[[Module, Symbol], String]
|
17
|
-
attr_reader :c2a
|
18
|
-
|
19
|
-
# This is the inverse of c2a, for inverse lookups.
|
20
|
-
#
|
21
|
-
# @sig Hash[String, [Module, Symbol]]
|
22
|
-
attr_reader :a2c
|
23
|
-
|
24
|
-
# @sig () -> void
|
25
|
-
def initialize
|
26
|
-
@c2a = {}
|
27
|
-
@a2c = {}
|
28
|
-
end
|
29
|
-
|
30
|
-
# @sig (Module, Symbol, String) -> void
|
31
|
-
def define(parent, cname, abspath)
|
32
|
-
parent.autoload(cname, abspath)
|
33
|
-
cref = [parent, cname]
|
34
|
-
c2a[cref] = abspath
|
35
|
-
a2c[abspath] = cref
|
36
|
-
end
|
37
|
-
|
38
|
-
# @sig () { () -> [[Module, Symbol], String] } -> void
|
39
|
-
def each(&block)
|
40
|
-
c2a.each(&block)
|
41
|
-
end
|
42
|
-
|
43
|
-
# @sig (Module, Symbol) -> String?
|
44
|
-
def abspath_for(parent, cname)
|
45
|
-
c2a[[parent, cname]]
|
46
|
-
end
|
47
|
-
|
48
|
-
# @sig (String) -> [Module, Symbol]?
|
49
|
-
def cref_for(abspath)
|
50
|
-
a2c[abspath]
|
51
|
-
end
|
52
|
-
|
53
|
-
# @sig (String) -> [Module, Symbol]?
|
54
|
-
def delete(abspath)
|
55
|
-
cref = a2c.delete(abspath)
|
56
|
-
c2a.delete(cref)
|
57
|
-
cref
|
58
|
-
end
|
59
|
-
|
60
|
-
# @sig () -> void
|
61
|
-
def clear
|
62
|
-
c2a.clear
|
63
|
-
a2c.clear
|
64
|
-
end
|
65
|
-
|
66
|
-
# @sig () -> bool
|
67
|
-
def empty?
|
68
|
-
c2a.empty? && a2c.empty?
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|