zeitwerk 1.3.2 → 1.3.3

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: 40e2919df324c67a85e00ac31349b96349b1a74a39e97e3f41c513258f108542
4
- data.tar.gz: 17c8c31d6a89e4ead544d1bc35143f548331923106decb05be67ebf57daf1bce
3
+ metadata.gz: ed6569d242e6aec3f736aef043e5c949ce12365d8b1647195820512b17185423
4
+ data.tar.gz: d046e7d1b35242a562ab09b7bea7a865e43a99b3a03c336fac86e2528b3fa2e5
5
5
  SHA512:
6
- metadata.gz: 455ff00c99726bb3003cebfcd4d264a4288a84d3d6d5bc7e8005ed4f0e7d66eff2abf3670b474bbeb5ca0a5517e1e7e316df64ccc065775b60e9b1822e5664cc
7
- data.tar.gz: 4971b4baec41fcffa1075248dbb714e456b2a0c37e193bd4ad47f81c658751dcf9de687ed023d4b0e00a67e57c4fa219ff7db6fe82437901774c6a0e59861dbf
6
+ metadata.gz: 3e2c325e9f18a1c81ea64fd6c6078bdba1bdeaed67bbbf316f9294f2b5901d172e7fd0bde3bf256a3049fe7ca363efa0a0d02f246acef53b8e6aed83b43db738
7
+ data.tar.gz: 321d32b46d05e8eb1e1ce20d7936b0ef42f0f57a89d2f4243d8d2da2421f02b7096e7db88f83e6cc37f9f87e5e7df3c55e74ed7e6ac08c9c27f7a4f251882125
@@ -47,15 +47,6 @@ module Zeitwerk
47
47
  disable_tracer_if_unneeded
48
48
  end
49
49
 
50
- # Utility for the test suite
51
- #
52
- # @private
53
- # @return [void]
54
- def teardown
55
- cpaths.clear
56
- tracer.disable
57
- end
58
-
59
50
  def disable_tracer_if_unneeded
60
51
  mutex.synchronize do
61
52
  tracer.disable if cpaths.empty?
@@ -67,7 +58,7 @@ module Zeitwerk
67
58
  @mutex = Mutex.new
68
59
  @tracer = TracePoint.new(:class) do |event|
69
60
  # Note that it makes sense to compute the hash code unconditionally,
70
- # because if cpaths was empty the trace point would be disabled.
61
+ # because the trace point is disabled if cpaths is empty.
71
62
  if loader = cpaths.delete(event.self.name)
72
63
  loader.on_namespace_loaded(event.self)
73
64
  disable_tracer_if_unneeded
@@ -415,7 +415,37 @@ module Zeitwerk
415
415
  # @param cname [String]
416
416
  # @return [String, nil]
417
417
  def autoload_for?(parent, cname)
418
- parent.autoload?(cname) || Registry.inception?(cpath(parent, cname))
418
+ strict_autoload_path(parent, cname) || Registry.inception?(cpath(parent, cname))
419
+ end
420
+
421
+ # The autoload? predicate takes into account the ancestor chain of the
422
+ # receiver, like const_defined? and other methods in the constants API do.
423
+ #
424
+ # For example, given
425
+ #
426
+ # class A
427
+ # autoload :X, "x.rb"
428
+ # end
429
+ #
430
+ # class B < A
431
+ # end
432
+ #
433
+ # B.autoload?(:X) returns "x.rb".
434
+ #
435
+ # We need a way to strictly check in parent ignoring ancestors.
436
+ #
437
+ # @param parent [Module]
438
+ # @param cname [String]
439
+ # @return [String, nil]
440
+ def strict_autoload_path(parent, cname)
441
+ if autoload_path = parent.autoload?(cname)
442
+ # Due to the use cases we have, we are done if parent is a Module.
443
+ return autoload_path unless parent.is_a?(Class)
444
+ # Since file and constant names match, if both parent and one of its
445
+ # ancestors have an autoload for the same cname, their autoload paths
446
+ # cannot be equal.
447
+ return autoload_path unless parent.superclass.autoload?(cname) == autoload_path
448
+ end
419
449
  end
420
450
 
421
451
  # This method is called this way because I prefer `preload` to be the method
@@ -137,16 +137,6 @@ module Zeitwerk
137
137
  autoloads.delete_if { |_path, object| object == loader }
138
138
  inceptions.delete_if { |_cpath, (_path, object)| object == loader }
139
139
  end
140
-
141
- # Utility for the test suite
142
- #
143
- # @private
144
- # @return [void]
145
- def teardown
146
- loaders.each(&:unload)
147
- loaders.clear
148
- loaders_managing_gems.clear
149
- end
150
140
  end
151
141
 
152
142
  @loaders = []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "1.3.2"
4
+ VERSION = "1.3.3"
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.2
4
+ version: 1.3.3
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-06 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem
@@ -29,7 +29,6 @@ files:
29
29
  - lib/zeitwerk/kernel.rb
30
30
  - lib/zeitwerk/loader.rb
31
31
  - lib/zeitwerk/loader/callbacks.rb
32
- - lib/zeitwerk/ordered_set.rb
33
32
  - lib/zeitwerk/registry.rb
34
33
  - lib/zeitwerk/version.rb
35
34
  homepage: https://github.com/fxn/zeitwerk
@@ -1,21 +0,0 @@
1
- module Zeitwerk
2
- class OrderedSet
3
- def initialize
4
- @set = {}
5
- end
6
-
7
- def add(object)
8
- @set[object] = true
9
- end
10
-
11
- def del(object)
12
- @set.delete(object)
13
- end
14
-
15
- def each
16
- @set.each_key do |key|
17
- yield key
18
- end
19
- end
20
- end
21
- end