zeitwerk 2.5.0.beta2 → 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 +14 -2
- data/lib/zeitwerk/loader/config.rb +3 -10
- data/lib/zeitwerk/loader.rb +15 -6
- data/lib/zeitwerk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c75f8cc8ed4e3df2f4bf5822402b5d1179e80d1bd2680efda63302f082dc366
|
4
|
+
data.tar.gz: ee91b83fb9c7e15c9502a3200c3d0a5cb785f5f2e9f75cd419e57bc335691784
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2ccad2ec4ca741a01432875eb683307eeb9840b278a3fff45ec74d3b1c2892c6953e7ef18b42cca40bfb09ca21f952c7aadf8653fc67f5e7a29b40e07e8bb74
|
7
|
+
data.tar.gz: b74645e665af729b8fd3a2fd6fcc6da86bcc953979f0f7db4b70fffa67e09e399615158acdfac996aaf083c28f538dde90f98b7682f9feb5331bdc498f2f24a5
|
data/README.md
CHANGED
@@ -49,6 +49,8 @@
|
|
49
49
|
- [Supported Ruby versions](#supported-ruby-versions)
|
50
50
|
- [Testing](#testing)
|
51
51
|
- [Motivation](#motivation)
|
52
|
+
- [Kerner#require is brittle](#kernerrequire-is-brittle)
|
53
|
+
- [Rails autoloading was brittle](#rails-autoloading-was-brittle)
|
52
54
|
- [Thanks](#thanks)
|
53
55
|
- [License](#license)
|
54
56
|
|
@@ -925,9 +927,19 @@ and run `bin/test`.
|
|
925
927
|
<a id="markdown-motivation" name="motivation"></a>
|
926
928
|
## Motivation
|
927
929
|
|
928
|
-
|
930
|
+
<a id="markdown-kernerrequire-is-brittle" name="kernerrequire-is-brittle"></a>
|
931
|
+
### Kerner#require is brittle
|
929
932
|
|
930
|
-
|
933
|
+
Since `require` has global side-effects, and there is no static way to verify that you have issued the `require` calls for code that your file depends on, in practice it is very easy to forget some. That introduces bugs that depend on the load order.
|
934
|
+
|
935
|
+
Also, if the project has namespaces, setting things up and getting client code to load things in a consistent way needs discipline. For example, `require "foo/bar"` may define `Foo`, instead of reopen it. That may be a broken window, giving place to superclass mismatches or partially-defined namespaces.
|
936
|
+
|
937
|
+
With Zeitwerk, you just name things following conventions and done. Things are available everywhere, and descend is always orderly. Without effort and without broken windows.
|
938
|
+
|
939
|
+
<a id="markdown-rails-autoloading-was-brittle" name="rails-autoloading-was-brittle"></a>
|
940
|
+
### Rails autoloading was brittle
|
941
|
+
|
942
|
+
Autoloading in Rails was based on `const_missing` up to Rails 5. That callback lacks fundamental information like the nesting or the resolution algorithm being used. Because of that, Rails autoloading was not able to match Ruby's semantics, and that introduced a series of issues. Zeitwerk is based on a different technique and fixed Rails autoloading starting with Rails 6.
|
931
943
|
|
932
944
|
<a id="markdown-thanks" name="thanks"></a>
|
933
945
|
## Thanks
|
@@ -247,17 +247,10 @@ module Zeitwerk::Loader::Config
|
|
247
247
|
|
248
248
|
# @private
|
249
249
|
# @sig (String) -> bool
|
250
|
-
def
|
251
|
-
|
252
|
-
|
253
|
-
return false if dir.start_with?(ignored_path + "/")
|
250
|
+
def ignores?(abspath)
|
251
|
+
ignored_paths.any? do |ignored_path|
|
252
|
+
ignored_path == abspath || (dir?(ignored_path) && abspath.start_with?(ignored_path + "/"))
|
254
253
|
end
|
255
|
-
|
256
|
-
root_dirs.each_key do |root_dir|
|
257
|
-
return true if root_dir.start_with?(dir) || dir.start_with?(root_dir + "/")
|
258
|
-
end
|
259
|
-
|
260
|
-
false
|
261
254
|
end
|
262
255
|
|
263
256
|
private
|
data/lib/zeitwerk/loader.rb
CHANGED
@@ -454,12 +454,21 @@ module Zeitwerk
|
|
454
454
|
def raise_if_conflicting_directory(dir)
|
455
455
|
self.class.mutex.synchronize do
|
456
456
|
Registry.loaders.each do |loader|
|
457
|
-
if loader
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
457
|
+
next if loader == self
|
458
|
+
next if loader.ignores?(dir)
|
459
|
+
|
460
|
+
dir = dir + "/"
|
461
|
+
loader.root_dirs.each do |root_dir, _namespace|
|
462
|
+
next if ignores?(root_dir)
|
463
|
+
|
464
|
+
root_dir = root_dir + "/"
|
465
|
+
if dir.start_with?(root_dir) || root_dir.start_with?(dir)
|
466
|
+
require "pp" # Needed for pretty_inspect, even in Ruby 2.5.
|
467
|
+
raise Error,
|
468
|
+
"loader\n\n#{pretty_inspect}\n\nwants to manage directory #{dir.chop}," \
|
469
|
+
" which is already managed by\n\n#{loader.pretty_inspect}\n"
|
470
|
+
EOS
|
471
|
+
end
|
463
472
|
end
|
464
473
|
end
|
465
474
|
end
|
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.5.0.
|
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: 2021-
|
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
|