Skip to content

Commit d53b7b2

Browse files
Bart de Waterbdewater
Bart de Water
authored andcommitted
Add code loading best practices
1 parent 3d59910 commit d53b7b2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.adoc

+19
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,25 @@ freeze_time
18771877

18781878
If your projects depends on various external processes use https://github.com/ddollar/foreman[foreman] to manage them.
18791879

1880+
== Code loading [[code-loading]]
1881+
1882+
=== Lazy load hooks
1883+
1884+
Use https://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html[lazy load hooks] to patch Rails core classes, so they are not forcible loaded early.
1885+
1886+
[source,ruby]
1887+
----
1888+
# bad
1889+
ActiveRecord::Base.include(MyClass)
1890+
1891+
# good
1892+
ActiveSupport.on_load(:active_record) { include MyClass }
1893+
----
1894+
1895+
=== Zeitwerk check in CI
1896+
1897+
Run `bin/rails zeitwerk:check` in your CI to ensure all application code is eager loaded correctly like in production.
1898+
18801899
== Further Reading
18811900

18821901
There are a few excellent resources on Rails style, that you should consider if you have time to spare:

0 commit comments

Comments
 (0)