zeitwerk 2.3.1 → 2.4.0
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 +4 -4
- data/README.md +16 -0
- data/lib/zeitwerk/inflector.rb +1 -1
- data/lib/zeitwerk/loader.rb +17 -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: 682fa352a9d6d4bf68d07cf2cbfbb539de3cfec4e8af2f930894ab27c707ca93
|
4
|
+
data.tar.gz: 1e7ce6157e6046cdb60f0f1b531f1f39fb97cad3537392114be5cf84dae672c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e308baba1a8fbe4d7c64d7195c753d795a53caefa7264d2404117cb620f2081f6b0fc05c056dafb035b44430102e4472b7eb9fb3a4fd9d70aa124b7f9a3a8313
|
7
|
+
data.tar.gz: 5139d5abaeed86e256493b592460b13b19fd7602f7c099f7017b55af9f16a91429e84074a4e31fe79bf28235e02cbba3055cc4bda579bbc7de2a391c5997a393
|
data/README.md
CHANGED
@@ -139,6 +139,22 @@ app/models/user.rb -> User
|
|
139
139
|
app/controllers/admin/users_controller.rb -> Admin::UsersController
|
140
140
|
```
|
141
141
|
|
142
|
+
Alternatively, you can associate a custom namespace to a root directory by passing a class or module object in the optional `namespace` keyword argument.
|
143
|
+
|
144
|
+
For example, Active Job queue adapters have to define a constant after their name in `ActiveJob::QueueAdapters`.
|
145
|
+
|
146
|
+
So, if you declare
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
require "active_job"
|
150
|
+
require "active_job/queue_adapters"
|
151
|
+
loader.push_dir("#{__dir__}/adapters", namespace: ActiveJob::QueueAdapters)
|
152
|
+
```
|
153
|
+
|
154
|
+
your adapter can be stored directly in that directory instead of the canonical `lib/active_job/queue_adapters`.
|
155
|
+
|
156
|
+
Please, note that the given namespace must be non-reloadable, though autoloaded constants in that namespace can be. That is, if you associate `app/api` with an existing `Api` module, that module should not be reloadable. However, if the project defines and autoloads the class `Api::V2::Deliveries`, that one can be reloaded.
|
157
|
+
|
142
158
|
<a id="markdown-implicit-namespaces" name="implicit-namespaces"></a>
|
143
159
|
### Implicit namespaces
|
144
160
|
|
data/lib/zeitwerk/inflector.rb
CHANGED
@@ -15,7 +15,7 @@ module Zeitwerk
|
|
15
15
|
# @param _abspath [String]
|
16
16
|
# @return [String]
|
17
17
|
def camelize(basename, _abspath)
|
18
|
-
overrides[basename] || basename.split('_').
|
18
|
+
overrides[basename] || basename.split('_').each(&:capitalize!).join
|
19
19
|
end
|
20
20
|
|
21
21
|
# Configures hard-coded inflections:
|
data/lib/zeitwerk/loader.rb
CHANGED
@@ -190,13 +190,19 @@ module Zeitwerk
|
|
190
190
|
# or descendants.
|
191
191
|
#
|
192
192
|
# @param path [<String, Pathname>]
|
193
|
+
# @param namespace [Class, Module]
|
193
194
|
# @raise [Zeitwerk::Error]
|
194
195
|
# @return [void]
|
195
|
-
def push_dir(path)
|
196
|
+
def push_dir(path, namespace: Object)
|
197
|
+
# Note that Class < Module.
|
198
|
+
unless namespace.is_a?(Module)
|
199
|
+
raise Error, "#{namespace.inspect} is not a class or module object, should be"
|
200
|
+
end
|
201
|
+
|
196
202
|
abspath = File.expand_path(path)
|
197
203
|
if dir?(abspath)
|
198
204
|
raise_if_conflicting_directory(abspath)
|
199
|
-
root_dirs[abspath] =
|
205
|
+
root_dirs[abspath] = namespace
|
200
206
|
else
|
201
207
|
raise Error, "the root directory #{abspath} does not exist"
|
202
208
|
end
|
@@ -268,7 +274,9 @@ module Zeitwerk
|
|
268
274
|
mutex.synchronize do
|
269
275
|
break if @setup
|
270
276
|
|
271
|
-
actual_root_dirs.each
|
277
|
+
actual_root_dirs.each do |root_dir, namespace|
|
278
|
+
set_autoloads_in_dir(root_dir, namespace)
|
279
|
+
end
|
272
280
|
do_preload
|
273
281
|
|
274
282
|
@setup = true
|
@@ -368,8 +376,11 @@ module Zeitwerk
|
|
368
376
|
mutex.synchronize do
|
369
377
|
break if @eager_loaded
|
370
378
|
|
371
|
-
queue =
|
372
|
-
|
379
|
+
queue = []
|
380
|
+
actual_root_dirs.each do |root_dir, namespace|
|
381
|
+
queue << [namespace, root_dir] unless eager_load_exclusions.member?(root_dir)
|
382
|
+
end
|
383
|
+
|
373
384
|
while to_eager_load = queue.shift
|
374
385
|
namespace, dir = to_eager_load
|
375
386
|
|
@@ -498,7 +509,7 @@ module Zeitwerk
|
|
498
509
|
|
499
510
|
# @return [<String>]
|
500
511
|
def actual_root_dirs
|
501
|
-
root_dirs.
|
512
|
+
root_dirs.reject do |root_dir, _namespace|
|
502
513
|
!dir?(root_dir) || ignored_paths.member?(root_dir)
|
503
514
|
end
|
504
515
|
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.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xavier Noria
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2
|
14
14
|
Zeitwerk implements constant autoloading with Ruby semantics. Each gem
|