Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code loading best practices #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 forcibly 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