Document that load hooks run if already triggered

After first learning of this in c2a3ff0 and later discussion about cross
component dependencies, it makes sense to document it explicitly.
This commit is contained in:
Hartley McGuire 2022-06-23 17:34:41 -04:00
parent 9badb0f794
commit 31d2468a25
No known key found for this signature in database
GPG Key ID: E823FC1403858A82
1 changed files with 14 additions and 1 deletions

View File

@ -26,6 +26,18 @@ module ActiveSupport
# run_load_hooks will then execute all the hooks that were registered
# with the on_load method. In the case of the above example, it will
# execute the block of code that is in the +initializer+.
#
# Registering a hook that has already run results in that hook executing
# immediately. This allows hooks to be nested for code that relies on
# multiple lazily loaded components:
#
# initializer "action_text.renderer" do
# ActiveSupport.on_load(:action_controller_base) do
# ActiveSupport.on_load(:action_text_content) do
# self.default_renderer = Class.new(ActionController::Base).renderer
# end
# end
# end
module LazyLoadHooks
def self.extended(base) # :nodoc:
base.class_eval do
@ -36,7 +48,8 @@ module ActiveSupport
end
# Declares a block that will be executed when a Rails component is fully
# loaded.
# loaded. If the component has already loaded, the block is executed
# immediately.
#
# Options:
#