Skip to content

Commit 9e4d31c

Browse files
committed
More edits to the classic migration guide
1 parent f14b19a commit 9e4d31c

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

guides/source/classic_to_zeitwerk_howto.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Hold on, I am eager loading the application.
162162
All is good!
163163
```
164164

165-
#### Concerns
165+
### Concerns
166166

167167
You can autoload and eager load from a standard structure like
168168

@@ -175,7 +175,7 @@ In that case, `app/models/concerns` is assumed to be a root directory (because i
175175

176176
The `Concerns::` namespace worked with the classic autoloader as a side-effect of the implementation, but it was not really an intended behavior. An application using `Concerns::` needs to rename those classes and modules to be able to run in `zeitwerk` mode.
177177

178-
#### Having `app` in the autoload paths
178+
### Having `app` in the autoload paths
179179

180180
Some projects want something like `app/api/base.rb` to define `API::Base`, and add `app` to the autoload paths to accomplish that in `classic` mode.
181181

@@ -188,7 +188,7 @@ If you want to keep that structure, you'll need to delete the subdirectory from
188188
ActiveSupport::Dependencies.autoload_paths.delete("#{Rails.root}/app/api")
189189
```
190190

191-
#### Autoloaded Constants and Explicit Namespaces
191+
### Autoloaded Constants and Explicit Namespaces
192192

193193
If a namespace is defined in a file, as `Hotel` is here:
194194

@@ -222,7 +222,7 @@ won't work, child objects like `Hotel::Pricing` won't be found.
222222

223223
This restriction only applies to explicit namespaces. Classes and modules not defining a namespace can be defined using those idioms.
224224

225-
#### One file, one constant (at the same top-level)
225+
### One file, one constant (at the same top-level)
226226

227227
In `classic` mode you could technically define several constants at the same top-level and have them all reloaded. For example, given
228228

@@ -253,7 +253,23 @@ end
253253

254254
If the application reloads `Foo`, it will reload `Foo::InnerClass` too.
255255

256-
#### Spring and the `test` Environment
256+
### Globs in `config.autoload_paths`
257+
258+
Beware of configurations like
259+
260+
```ruby
261+
config.autoload_paths += Dir["#{config.root}/lib/**/"]
262+
```
263+
264+
Every element of `config.autoload_paths` should represent the top-level namespace (`Object`) and they cannot be nested in consequence (with the exception of `concerns` directories explained above).
265+
266+
To fix this, just remove the wildcards:
267+
268+
```ruby
269+
config.autoload_paths << "#{config.root}/lib"
270+
```
271+
272+
### Spring and the `test` Environment
257273

258274
Spring reloads the application code if something changes. In the `test` environment you need to enable reloading for that to work:
259275

@@ -270,7 +286,7 @@ reloading is disabled because config.cache_classes is true
270286

271287
This has no performance penalty.
272288

273-
#### Bootsnap
289+
### Bootsnap
274290

275291
Please make sure to depend on at least Bootsnap 1.4.4.
276292

@@ -310,22 +326,6 @@ RSpec.describe "Zeitwerk compliance" do
310326
end
311327
```
312328

313-
### Globs in `config.autoload_paths`
314-
315-
Beware of configurations like
316-
317-
```ruby
318-
config.autoload_paths += Dir["#{config.root}/lib/**/"]
319-
```
320-
321-
Every element of `config.autoload_paths` should represent the top-level namespace (`Object`) and they cannot be nested in consequence (with the exception of `concerns` directories explained above).
322-
323-
To fix this, just remove the wildcards:
324-
325-
```ruby
326-
config.autoload_paths << "#{config.root}/lib"
327-
```
328-
329329
New Features You Can Leverage
330330
-----------------------------
331331

0 commit comments

Comments
 (0)