aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/initialization.md
diff options
context:
space:
mode:
authorCory Foy <github@cornetdesign.com>2013-10-09 16:16:12 -0400
committerCory Foy <github@cornetdesign.com>2013-10-09 16:16:12 -0400
commit7a1e7b38f2bad0234d5137d431fda4972a9c1932 (patch)
tree43941b628c9d269a38ca2660d5a42ea4a15df733 /guides/source/initialization.md
parentbdeeba1c558f56df2bf240643d74f38f2b9ae98f (diff)
downloadrails-7a1e7b38f2bad0234d5137d431fda4972a9c1932.tar.gz
rails-7a1e7b38f2bad0234d5137d431fda4972a9c1932.tar.bz2
rails-7a1e7b38f2bad0234d5137d431fda4972a9c1932.zip
Modifies the initialization guide to make the initializers process clearer and remove a TODO. [ci skip]
Diffstat (limited to 'guides/source/initialization.md')
-rw-r--r--guides/source/initialization.md22
1 files changed, 16 insertions, 6 deletions
diff --git a/guides/source/initialization.md b/guides/source/initialization.md
index 91d12b4432..fe6b1ad906 100644
--- a/guides/source/initialization.md
+++ b/guides/source/initialization.md
@@ -468,14 +468,24 @@ def initialize!(group=:default) #:nodoc:
end
```
-As you can see, you can only initialize an app once. This is also where the initializers are run.
+As you can see, you can only initialize an app once. The initializers are run through
+the `run_initializers` method which is defined in `railties/lib/rails/initializable.rb`
-TODO: review this
+```ruby
+def run_initializers(group=:default, *args)
+ return if instance_variable_defined?(:@ran)
+ initializers.tsort_each do |initializer|
+ initializer.run(*args) if initializer.belongs_to?(group)
+ end
+ @ran = true
+end
+```
-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.
+The run_initializers code itself is tricky. What Rails is doing here is
+traversing all the class ancestors looking for those that respond to an
+`initializers` method. It then sorts the ancestors by name, and runs them.
+For example, the `Engine` class will make all the engines available by
+providing an `initializers` method on them.
The `Rails::Application` class, as defined in `railties/lib/rails/application.rb`
defines `bootstrap`, `railtie`, and `finisher` initializers. The `bootstrap` initializers