aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorOscar Del Ben <info@oscardelben.com>2012-06-13 08:48:45 -0700
committerOscar Del Ben <info@oscardelben.com>2012-06-13 08:48:45 -0700
commit1f07ff97ab416ba54b4cecde2be1a22341dfa09e (patch)
tree658f79c8f2f9c1ec26dd4337c2c1ed3dfe616180 /guides/source
parent81fd371f138b92f4783ecd42ff0d656715ed118d (diff)
downloadrails-1f07ff97ab416ba54b4cecde2be1a22341dfa09e.tar.gz
rails-1f07ff97ab416ba54b4cecde2be1a22341dfa09e.tar.bz2
rails-1f07ff97ab416ba54b4cecde2be1a22341dfa09e.zip
Add initialize! explanation
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/initialization.textile25
1 files changed, 25 insertions, 0 deletions
diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile
index 7d78f0a94c..bf901508c8 100644
--- a/guides/source/initialization.textile
+++ b/guides/source/initialization.textile
@@ -547,3 +547,28 @@ your application namespace, you go back to +config/environment.rb+,
where your application is initialized. For example, if you application was called
+Blog+, here you would find +Blog::Application.initialize!+, which is
defined in +rails/application.rb+
+
+h4. +railties/lib/rails/application.rb+
+
+The +initialize!+ method looks like this:
+
+<ruby>
+def initialize!(group=:default) #:nodoc:
+ raise "Application has been already initialized." if @initialized
+ run_initializers(group, self)
+ @initialized = true
+ self
+end
+</ruby>
+
+As you can see, you can only initialize an app once. This is also where the initializers are run.
+
+TODO: review this
+
+The initializers code itself is tricky. What Rails is doing here is it
+traverses all the class ancestors looking for an +initializers+ method,
+sorting them and running them. For example, the +Engine+ class will make
+all the engines available by providing the +initializers+ method.
+
+After this is done we go back to +Rack::Server+
+