zeitwerk 2.5.0.beta → 2.5.0.beta2

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: 7ac5e0ce2eba71a2099ead24de8762e3e737656ff4bcae57c83bb5797e922f72
4
- data.tar.gz: 85e7c762a5164301ba5bcce82a31e6c49bc7c6caff2b4abff23c425f10374c69
3
+ metadata.gz: 64ea17faefd07265c96bd8c49c9a4e14170612f85f868c03df91aa4511e473e3
4
+ data.tar.gz: fb98b0f841e49016039d73310d50563e8e6c3bbcf4c16f2d4441b241cb266647
5
5
  SHA512:
6
- metadata.gz: f258acabd660f54702eb904550a109b08bdacff2cecc92d610376376f77ccf70ed421e09c64144930d2a145ebbedb7e9c3c26ff21ad2c1b40dd0537d9947b4d4
7
- data.tar.gz: 1612dc2d505fe37b748d81a9055e36a91f9f73267ac273b39a4cbea3736cdd1baa4c557e3059d8f3a9a9807d450e29f3d75c7cb18c94c37ded70768444313336
6
+ metadata.gz: 3dfdc023489a4b7306c2bbac6f56234ff4a80887820967ff691fd9b13609ea256ba5bca301870d5e5b35d26c09ece01158a984d3093fa63d0de0bd3d9cdff458
7
+ data.tar.gz: 4860a04e9e489251ce43e56f37c7213ac3dda7c301f9dff1826d7e5f2567b992bfac35f645dab67a356bb8a4024c29d0fd8431f91896f7a254bf747864dd8ef0
data/README.md CHANGED
@@ -433,11 +433,13 @@ On reloading, client code has to update anything that would otherwise be storing
433
433
  <a id="markdown-inflection" name="inflection"></a>
434
434
  ### Inflection
435
435
 
436
- Each individual loader needs an inflector to figure out which constant path would a given file or directory map to. Zeitwerk ships with two basic inflectors.
436
+ Each individual loader needs an inflector to figure out which constant path would a given file or directory map to. Zeitwerk ships with two basic inflectors, and you can define your own.
437
437
 
438
438
  <a id="markdown-zeitwerkinflector" name="zeitwerkinflector"></a>
439
439
  #### Zeitwerk::Inflector
440
440
 
441
+ Each loader instantiated with `Zeitwerk::Loader.new` has an inflector of this type by default.
442
+
441
443
  This is a very basic inflector that converts snake case to camel case:
442
444
 
443
445
  ```
@@ -464,16 +466,16 @@ loader.inflector.inflect "mysql_adapter" => "MySQLAdapter"
464
466
 
465
467
  Overrides need to be configured before calling `setup`.
466
468
 
467
- There are no inflection rules or global configuration that can affect this inflector. It is deterministic.
468
-
469
- Loaders instantiated with `Zeitwerk::Loader.new` have an inflector of this type, independent of each other.
469
+ The inflectors of different loaders are independent of each other. There are no global inflection rules or global configuration that can affect this inflector. It is deterministic.
470
470
 
471
471
  <a id="markdown-zeitwerkgeminflector" name="zeitwerkgeminflector"></a>
472
472
  #### Zeitwerk::GemInflector
473
473
 
474
+ Each loader instantiated with `Zeitwerk::Loader.for_gem` has an inflector of this type by default.
475
+
474
476
  This inflector is like the basic one, except it expects `lib/my_gem/version.rb` to define `MyGem::VERSION`.
475
477
 
476
- Loaders instantiated with `Zeitwerk::Loader.for_gem` have an inflector of this type, independent of each other.
478
+ The inflectors of different loaders are independent of each other. There are no global inflection rules or global configuration that can affect this inflector. It is deterministic.
477
479
 
478
480
  <a id="markdown-custom-inflector" name="custom-inflector"></a>
479
481
  #### Custom inflector
@@ -580,7 +582,7 @@ end
580
582
 
581
583
  Some uses cases:
582
584
 
583
- * Doing something with an autoloadable class or module in a Rails application during initialization, in a way that plays well with reloading. As in the previous example.
585
+ * Doing something with a reloadable class or module in a Rails application during initialization, in a way that plays well with reloading. As in the previous example.
584
586
  * Delaying the execution of the block until the class is loaded for performance.
585
587
  * Delaying the execution of the block until the class is loaded because it follows the adapter pattern and better not to load the class if the user does not need it.
586
588
 
@@ -41,7 +41,7 @@ module Zeitwerk
41
41
 
42
42
  # @private
43
43
  # @sig (Zeitwerk::Loader) -> void
44
- def unregister(loader)
44
+ def unregister_loader(loader)
45
45
  cpaths.delete_if { |_cpath, l| l == loader }
46
46
  disable_tracer_if_unneeded
47
47
  end
@@ -121,7 +121,10 @@ module Zeitwerk
121
121
  # else, they are eligible for garbage collection, which would effectively
122
122
  # unload them.
123
123
  #
124
- # @private
124
+ # This method is public but undocumented. Main interface is `reload`, which
125
+ # means `unload` + `setup`. This one is avaiable to be used together with
126
+ # `unregister`, which is undocumented too.
127
+ #
125
128
  # @sig () -> void
126
129
  def unload
127
130
  mutex.synchronize do
@@ -176,7 +179,7 @@ module Zeitwerk
176
179
  lazy_subdirs.clear
177
180
 
178
181
  Registry.on_unload(self)
179
- ExplicitNamespace.unregister(self)
182
+ ExplicitNamespace.unregister_loader(self)
180
183
 
181
184
  @setup = false
182
185
  @eager_loaded = false
@@ -267,6 +270,15 @@ module Zeitwerk
267
270
  to_unload.keys.freeze
268
271
  end
269
272
 
273
+ # This is a dangerous method.
274
+ #
275
+ # @experimental
276
+ # @sig () -> void
277
+ def unregister
278
+ Registry.unregister_loader(self)
279
+ ExplicitNamespace.unregister_loader(self)
280
+ end
281
+
270
282
  # --- Class methods ---------------------------------------------------------------------------
271
283
 
272
284
  class << self
@@ -73,6 +73,15 @@ module Zeitwerk
73
73
  loaders << loader
74
74
  end
75
75
 
76
+ # @private
77
+ # @sig (Zeitwerk::Loader) -> void
78
+ def unregister_loader(loader)
79
+ loaders.delete(loader)
80
+ loaders_managing_gems.delete_if { |_, l| l == loader }
81
+ autoloads.delete_if { |_, l| l == loader }
82
+ inceptions.delete_if { |_, (_, l)| l == loader }
83
+ end
84
+
76
85
  # This method returns always a loader, the same instance for the same root
77
86
  # file. That is how Zeitwerk::Loader.for_gem is idempotent.
78
87
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.5.0.beta"
4
+ VERSION = "2.5.0.beta2"
5
5
  end
data/lib/zeitwerk.rb CHANGED
@@ -11,4 +11,15 @@ module Zeitwerk
11
11
  require_relative "zeitwerk/kernel"
12
12
  require_relative "zeitwerk/error"
13
13
  require_relative "zeitwerk/version"
14
+
15
+ # This is a dangerous method.
16
+ #
17
+ # @experimental
18
+ # @sig () -> void
19
+ def self.with_loader
20
+ loader = Zeitwerk::Loader.new
21
+ yield loader
22
+ ensure
23
+ loader.unregister
24
+ end
14
25
  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.beta
4
+ version: 2.5.0.beta2
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-03 00:00:00.000000000 Z
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: 1.3.1
61
61
  requirements: []
62
- rubygems_version: 3.1.6
62
+ rubygems_version: 3.2.22
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Efficient and thread-safe constant autoloader