zeitwerk 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed6569d242e6aec3f736aef043e5c949ce12365d8b1647195820512b17185423
4
- data.tar.gz: d046e7d1b35242a562ab09b7bea7a865e43a99b3a03c336fac86e2528b3fa2e5
3
+ metadata.gz: 53e3caf01e7af10f0f12922ebbe41f400a27eee1fa8d47a1d580ba1bb421393b
4
+ data.tar.gz: 6b76087bdc7abec95aa7a70ee5c5b70cb7567e7b02c8dbb290852a3bda523089
5
5
  SHA512:
6
- metadata.gz: 3e2c325e9f18a1c81ea64fd6c6078bdba1bdeaed67bbbf316f9294f2b5901d172e7fd0bde3bf256a3049fe7ca363efa0a0d02f246acef53b8e6aed83b43db738
7
- data.tar.gz: 321d32b46d05e8eb1e1ce20d7936b0ef42f0f57a89d2f4243d8d2da2421f02b7096e7db88f83e6cc37f9f87e5e7df3c55e74ed7e6ac08c9c27f7a4f251882125
6
+ metadata.gz: 31aabb9e4c66028674508efa6dad871ece2893a3bb78e9c53d24be6721dbbd1a9f0960348ca5c7b33dc3e16670bd2c8b37eea3d813f6ce045b63410a73033a66
7
+ data.tar.gz: dc9f42aecb424d7695d48e831ec0ef70159538ded7abf470cc0a26195087aa8a3ce0d3a3a83c8978a88dda8fccb747013db60b0b1b2169e5a6c9ff1b30e94bb8
@@ -53,6 +53,21 @@ module Zeitwerk
53
53
  # @return [Set<String>]
54
54
  attr_reader :ignored_paths
55
55
 
56
+ # Keeps track of shadowed files.
57
+ #
58
+ # A shadowed file is a file managed by this autoloader that is skipped
59
+ # because its matching constant path has already been seen. Think $LOAD_PATH
60
+ # + require, only the first occurrence of a given relative name is loaded.
61
+ #
62
+ # If the existing occurrence is an autoload, we map the file name to the
63
+ # shadowing autoload path. If the existing occurrence is an already defined
64
+ # constant, the file name is mapped to the constant path, meaning it was
65
+ # loaded elsewhere.
66
+ #
67
+ # @private
68
+ # @return [{String => String}]
69
+ attr_reader :shadowed
70
+
56
71
  # Maps real absolute paths for which an autoload has been set to their
57
72
  # corresponding parent class or module and constant name.
58
73
  #
@@ -106,6 +121,7 @@ module Zeitwerk
106
121
  @autoloads = {}
107
122
  @loaded = Set.new
108
123
  @lazy_subdirs = {}
124
+ @shadowed = {}
109
125
 
110
126
  @mutex = Mutex.new
111
127
  @setup = false
@@ -216,6 +232,7 @@ module Zeitwerk
216
232
  autoloads.clear
217
233
  loaded.clear
218
234
  lazy_subdirs.clear
235
+ shadowed.clear
219
236
 
220
237
  Registry.on_unload(self)
221
238
  ExplicitNamespace.unregister(self)
@@ -249,7 +266,7 @@ module Zeitwerk
249
266
  while dir = queue.shift
250
267
  each_abspath(dir) do |abspath|
251
268
  if ruby?(abspath)
252
- require abspath
269
+ require abspath unless shadowed.key?(abspath)
253
270
  elsif dir?(abspath)
254
271
  queue << abspath
255
272
  end
@@ -370,7 +387,7 @@ module Zeitwerk
370
387
  def autoload_file(parent, cname, file)
371
388
  if autoload_path = autoload_for?(parent, cname)
372
389
  # First autoload for a Ruby file wins, just ignore subsequent ones.
373
- return if ruby?(autoload_path)
390
+ shadowed[file] = autoload_path and return if ruby?(autoload_path)
374
391
 
375
392
  # Override autovivification, we want the namespace to become the
376
393
  # class/module defined in this file.
@@ -379,7 +396,9 @@ module Zeitwerk
379
396
 
380
397
  set_autoload(parent, cname, file)
381
398
  register_explicit_namespace(cpath(parent, cname))
382
- elsif !cdef?(parent, cname)
399
+ elsif cdef?(parent, cname)
400
+ shadowed[file] = cpath(parent, cname)
401
+ else
383
402
  set_autoload(parent, cname, file)
384
403
  end
385
404
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "1.3.3"
4
+ VERSION = "1.3.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: 1.3.3
4
+ version: 1.3.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: 2019-03-11 00:00:00.000000000 Z
11
+ date: 2019-03-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem