diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-09 16:25:17 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-10-09 16:25:17 -0700 |
commit | ad0030b2608274c1ebfc07addf88b3fb7cf319ed (patch) | |
tree | 26157398e1db2a07b92c8b2032aea354f54ced1f /guides/source | |
parent | 729d3c05998ecd9e18e4d1e83cd14e5b609bd7f5 (diff) | |
parent | 7a1e7b38f2bad0234d5137d431fda4972a9c1932 (diff) | |
download | rails-ad0030b2608274c1ebfc07addf88b3fb7cf319ed.tar.gz rails-ad0030b2608274c1ebfc07addf88b3fb7cf319ed.tar.bz2 rails-ad0030b2608274c1ebfc07addf88b3fb7cf319ed.zip |
Merge pull request #12488 from CoryFoy/master
[ci skip] Modifies the initialization guide to make the initializers process clearer
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/initialization.md | 22 |
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 |