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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64ea17faefd07265c96bd8c49c9a4e14170612f85f868c03df91aa4511e473e3
4
- data.tar.gz: fb98b0f841e49016039d73310d50563e8e6c3bbcf4c16f2d4441b241cb266647
3
+ metadata.gz: 3c75f8cc8ed4e3df2f4bf5822402b5d1179e80d1bd2680efda63302f082dc366
4
+ data.tar.gz: ee91b83fb9c7e15c9502a3200c3d0a5cb785f5f2e9f75cd419e57bc335691784
5
5
  SHA512:
6
- metadata.gz: 3dfdc023489a4b7306c2bbac6f56234ff4a80887820967ff691fd9b13609ea256ba5bca301870d5e5b35d26c09ece01158a984d3093fa63d0de0bd3d9cdff458
7
- data.tar.gz: 4860a04e9e489251ce43e56f37c7213ac3dda7c301f9dff1826d7e5f2567b992bfac35f645dab67a356bb8a4024c29d0fd8431f91896f7a254bf747864dd8ef0
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
- 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. Zeitwerk provides a way to forget about `require` in your own code, just name things following conventions and done.
930
+ <a id="markdown-kernerrequire-is-brittle" name="kernerrequire-is-brittle"></a>
931
+ ### Kerner#require is brittle
929
932
 
930
- On the other hand, autoloading in Rails is based on `const_missing`, which lacks fundamental information like the nesting and the resolution algorithm that was being used. Because of that, Rails autoloading is not able to match Ruby's semantics and that introduces a series of gotchas. The original goal of this project was to bring a better autoloading mechanism for Rails 6.
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 manages?(dir)
251
- dir = dir + "/"
252
- ignored_paths.each do |ignored_path|
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
@@ -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 != self && loader.manages?(dir)
458
- require "pp"
459
- raise Error,
460
- "loader\n\n#{pretty_inspect}\n\nwants to manage directory #{dir}," \
461
- " which is already managed by\n\n#{loader.pretty_inspect}\n"
462
- EOS
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.5.0.beta2"
4
+ VERSION = "2.5.0.beta3"
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: 2.5.0.beta2
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-08-20 00:00:00.000000000 Z
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