Skip to content

Commit

Permalink
Add code loading best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart de Water authored and bdewater committed Sep 5, 2022
1 parent 3d59910 commit d53b7b2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,25 @@ freeze_time

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

== Code loading [[code-loading]]

=== Lazy load hooks

Use https://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html[lazy load hooks] to patch Rails core classes, so they are not forcible loaded early.

[source,ruby]
----
# bad
ActiveRecord::Base.include(MyClass)
# good
ActiveSupport.on_load(:active_record) { include MyClass }
----

=== Zeitwerk check in CI

Run `bin/rails zeitwerk:check` in your CI to ensure all application code is eager loaded correctly like in production.

== Further Reading

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

0 comments on commit d53b7b2

Please sign in to comment.