zeitwerk 2.6.0 → 2.6.1

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: d7c15f85768f681d78dd0a96b23e5bb92fe8955fe74d9ae0cefeb1b0a55b76f1
4
- data.tar.gz: 212a4b236b7d67c9413bd583bef540c0c9c090f5d0457af38b0681405bba3244
3
+ metadata.gz: cf4acabb8b402560402158aced0f30ae6bae5120dc65d719f4fb15c1385a2454
4
+ data.tar.gz: 0a297687455cf8c3924a64c5e36223c35b0f69712c807ee9bc70748f8c42ff37
5
5
  SHA512:
6
- metadata.gz: 4feeb02e4ec695895035a39d1a46d45bd8eb77a1d72e732c28387ff16f4c3e2ac10735195fa246179cfce2fe072ada05c0f661b599fd4bc44763d300e485b12d
7
- data.tar.gz: 0bd284cdfd10b1f27c7ad31ecd79c7bce9d76be46d3644941259ac7ee22ed425baac0cbcc340653547c873aecca6d5833c908e3009f58c4f0376be5402c9645b
6
+ metadata.gz: 1d6666a098ae430f452edcd8b5e458541f20b20c4ee5903c4d18fe19cdce5afe81d6311a1bff5f9412b18ae57274e9b13132f8d59d9189b0ccd6cf7711337d6e
7
+ data.tar.gz: a131561faa463e489f7e9c4898bc8e212b2f6814ba3ce634b7ef62e25467f38b88e4c63106e8d53ee933681e1f0dc196244d16f13c299d2ca0771ee4031655a1
data/README.md CHANGED
@@ -47,6 +47,7 @@
47
47
  - [Edge cases](#edge-cases)
48
48
  - [Beware of circular dependencies](#beware-of-circular-dependencies)
49
49
  - [Reopening third-party namespaces](#reopening-third-party-namespaces)
50
+ - [Introspection](#introspection)
50
51
  - [Encodings](#encodings)
51
52
  - [Rules of thumb](#rules-of-thumb)
52
53
  - [Debuggers](#debuggers)
@@ -249,7 +250,7 @@ app/controllers/admin/users_controller.rb -> Admin::UsersController
249
250
 
250
251
  and does not have a file called `admin.rb`, Zeitwerk automatically creates an `Admin` module on your behalf the first time `Admin` is used.
251
252
 
252
- For this to happen, the directory has to contain non-ignored Ruby files, directly or recursively, otherwise it is ignored. This condition is evaluated again on reloads.
253
+ For this to happen, the directory has to contain non-ignored Ruby files with extension `.rb`, directly or recursively, otherwise it is ignored. This condition is evaluated again on reloads.
253
254
 
254
255
  <a id="markdown-explicit-namespaces" name="explicit-namespaces"></a>
255
256
  ### Explicit namespaces
@@ -983,12 +984,36 @@ require "active_job"
983
984
  require "active_job/queue_adapters"
984
985
 
985
986
  require "zeitwerk"
986
- loader = Zeitwerk::Loader.for_gem
987
+ # By passign the flag, we acknowledge the extra directory lib/active_job
988
+ # has to be managed by the loader and no warning has to be issued for it.
989
+ loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
987
990
  loader.setup
988
991
  ```
989
992
 
990
993
  With that, when Zeitwerk scans the file system and reaches the gem directories `lib/active_job` and `lib/active_job/queue_adapters`, it detects the corresponding modules already exist and therefore understands it does not have to manage them. The loader just descends into those directories. Eventually will reach `lib/active_job/queue_adapters/awesome_queue.rb`, and since `ActiveJob::QueueAdapters::AwesomeQueue` is unknown, Zeitwerk will manage it. Which is what happens regularly with the files in your gem. On reload, the namespaces are safe, won't be reloaded. The loader only reloads what it manages, which in this case is the adapter itself.
991
994
 
995
+ <a id="markdown-introspection" name="introspection"></a>
996
+ ### Introspection
997
+
998
+ The method `Zeitwerk::Loader#dirs` returns an array with the absolute paths of the root directories as strings:
999
+
1000
+ ```ruby
1001
+ loader = Zeitwerk::Loader.new
1002
+ loader.push_dir(Pathname.new("/foo"))
1003
+ loader.dirs # => ["/foo"]
1004
+ ```
1005
+
1006
+ This method accepts an optional `namespaces` keyword argument. If truthy, the method returns a hash table instead. Keys are the absolute paths of the root directories as strings. Values are their corresponding namespaces, class or module objects:
1007
+
1008
+ ```ruby
1009
+ loader = Zeitwerk::Loader.new
1010
+ loader.push_dir(Pathname.new("/foo"))
1011
+ loader.push_dir(Pathname.new("/bar"), namespace: Bar)
1012
+ loader.dirs(namespaces: true) # => { "/foo" => Object, "/bar" => Bar }
1013
+ ```
1014
+
1015
+ These collections are read-only. Please add to them with `Zeitwerk::Loader#push_dir`.
1016
+
992
1017
  <a id="markdown-encodings" name="encodings"></a>
993
1018
  ### Encodings
994
1019
 
@@ -5,18 +5,19 @@ require "securerandom"
5
5
 
6
6
  module Zeitwerk::Loader::Config
7
7
  # Absolute paths of the root directories. Stored in a hash to preserve
8
- # order, easily handle duplicates, and also be able to have a fast lookup,
9
- # needed for detecting nested paths.
8
+ # order, easily handle duplicates, have a fast lookup needed for detecting
9
+ # nested paths, and store custom namespaces as values.
10
10
  #
11
- # "/Users/fxn/blog/app/assets" => true,
12
- # "/Users/fxn/blog/app/channels" => true,
11
+ # "/Users/fxn/blog/app/assets" => Object,
12
+ # "/Users/fxn/blog/app/channels" => Object,
13
+ # "/Users/fxn/blog/adapters" => ActiveJob::QueueAdapters,
13
14
  # ...
14
15
  #
15
16
  # This is a private collection maintained by the loader. The public
16
17
  # interface for it is `push_dir` and `dirs`.
17
18
  #
18
19
  # @private
19
- # @sig Hash[String, true]
20
+ # @sig Hash[String, Module]
20
21
  attr_reader :root_dirs
21
22
 
22
23
  # @sig #camelize
@@ -136,12 +137,20 @@ module Zeitwerk::Loader::Config
136
137
  @tag = tag.to_s
137
138
  end
138
139
 
139
- # Absolute paths of the root directories. This is a read-only collection,
140
- # please push here via `push_dir`.
140
+ # If `namespaces` is falsey (default), returns an array with the absolute
141
+ # paths of the root directories as strings. If truthy, returns a hash table
142
+ # instead. Keys are the absolute paths of the root directories as strings,
143
+ # values are their corresponding namespaces, class or module objects.
141
144
  #
142
- # @sig () -> Array[String]
143
- def dirs
144
- root_dirs.keys.freeze
145
+ # These are read-only collections, please add to them with `push_dir`.
146
+ #
147
+ # @sig () -> Array[String] | Hash[String, Module]
148
+ def dirs(namespaces: false)
149
+ if namespaces
150
+ root_dirs.clone
151
+ else
152
+ root_dirs.keys
153
+ end.freeze
145
154
  end
146
155
 
147
156
  # You need to call this method before setup in order to be able to reload.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zeitwerk
4
- VERSION = "2.6.0"
4
+ VERSION = "2.6.1"
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.6.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xavier Noria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-13 00:00:00.000000000 Z
11
+ date: 2022-09-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Zeitwerk implements constant autoloading with Ruby semantics. Each gem