aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/initialization.textile
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-07-29 12:52:15 -0400
committerNeeraj Singh <neerajdotname@gmail.com>2010-07-29 12:52:15 -0400
commita506d5a5241507afda5f57ca8953fbcbf4b91231 (patch)
tree80ff61a5328c70970a97752cd95ab7258909a0df /railties/guides/source/initialization.textile
parente42945333b1cb8e387699524b19fbad7ae23dcb7 (diff)
downloadrails-a506d5a5241507afda5f57ca8953fbcbf4b91231.tar.gz
rails-a506d5a5241507afda5f57ca8953fbcbf4b91231.tar.bz2
rails-a506d5a5241507afda5f57ca8953fbcbf4b91231.zip
updating documentation about lazy hooks in ActiveSupport
Diffstat (limited to 'railties/guides/source/initialization.textile')
-rw-r--r--railties/guides/source/initialization.textile19
1 files changed, 7 insertions, 12 deletions
diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile
index 305602e57d..28afdb3bd0 100644
--- a/railties/guides/source/initialization.textile
+++ b/railties/guides/source/initialization.textile
@@ -258,28 +258,23 @@ This file goes on to define some classes that will be automatically loaded using
h4. Lazy Hooks
-At the top if the +ActiveSupport::Autoload+ module is the +def self.extended+ method:
-
-<ruby>
- def self.extended(base)
- base.extend(LazyLoadHooks)
- end
-</ruby>
-
-This is called when we extend this module into one of our classes or modules, such is the case later on when we call +extend ActiveSupport::LazyLoadHooks+ not only in the +ActiveSupport+ module, but in all of the Railtie modules (+ActiveRecord+ and so on), as well as in a couple of places.
-
+ActiveSupport::LazyLoadHooks+ is responsible for defining methods used for running hooks that are defined during the initialization process, such as the one defined inside the +active_record.initialize_timezone+ initializer:
<ruby>
initializer "active_record.initialize_timezone" do
- ActiveRecord.base_hook do
+ ActiveSupport.on_load(:active_record) do
self.time_zone_aware_attributes = true
self.default_timezone = :utc
end
end
</ruby>
-When the initializer is ran it defines a +base_hook+ for +ActiveRecord+ and will only run it when +run_base_hooks+ is called, which in the case of Active Record, is ran after the entirety of +activerecord/lib/active_record/base.rb+ has been evaluated.
+When the initializer runs it invokes method +on_load+ for +ActiveRecord+ and the block passed to it would be called only when +run_load_hooks+ is called.
+When the entirety of +activerecord/lib/active_record/base.rb+ has been evaluated then +run_load_hooks+ is invoked. The very last line of +activerecord/lib/active_record/base.rb+ is:
+
+<ruby>
+ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
+</ruby>
h4. +require 'active_support'+ cont'd.