11# frozen_string_literal: true
22
33module ActiveSupport
4- # lazy_load_hooks allows Rails to lazily load a lot of components and thus
4+ # LazyLoadHooks allows Rails to lazily load a lot of components and thus
55 # making the app boot faster. Because of this feature now there is no need to
66 # require <tt>ActiveRecord::Base</tt> at boot time purely to apply
77 # configuration. Instead a hook is registered that applies configuration once
88 # <tt>ActiveRecord::Base</tt> is loaded. Here <tt>ActiveRecord::Base</tt> is
99 # used as example but this feature can be applied elsewhere too.
1010 #
11- # Here is an example where + on_load+ method is called to register a hook.
11+ # Here is an example where on_load method is called to register a hook.
1212 #
1313 # initializer 'active_record.initialize_timezone' do
1414 # ActiveSupport.on_load(:active_record) do
@@ -18,10 +18,14 @@ module ActiveSupport
1818 # end
1919 #
2020 # When the entirety of +ActiveRecord::Base+ has been
21- # evaluated then + run_load_hooks+ is invoked. The very last line of
21+ # evaluated then run_load_hooks is invoked. The very last line of
2222 # +ActiveRecord::Base+ is:
2323 #
2424 # ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
25+ #
26+ # run_load_hooks will then execute all the hooks that were registered
27+ # with the on_load method. In the case of the above example, it will
28+ # execute the block of code that is in the +initializer+.
2529 module LazyLoadHooks
2630 def self . extended ( base ) # :nodoc:
2731 base . class_eval do
@@ -46,6 +50,13 @@ def on_load(name, options = {}, &block)
4650 @load_hooks [ name ] << [ block , options ]
4751 end
4852
53+ # Executes all blocks registered to +name+ via on_load, using +base+ as the
54+ # evaluation context.
55+ #
56+ # ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
57+ #
58+ # In the case of the above example, it will execute all hooks registered
59+ # for +:active_record+ within the class +ActiveRecord::Base+.
4960 def run_load_hooks ( name , base = Object )
5061 @loaded [ name ] << base
5162 @load_hooks [ name ] . each do |hook , options |
0 commit comments