aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/application
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-05-15 06:08:55 -0700
committerwycats <wycats@gmail.com>2010-05-15 06:09:07 -0700
commit9cfeefb637b603ce41d3019c8baa95ea984620d7 (patch)
tree8503a2498cb2b111e672d72ed70502a02053d9e3 /railties/lib/rails/application
parent458f5712dce6d7f23931effe01b7f34b66e4ab3b (diff)
downloadrails-9cfeefb637b603ce41d3019c8baa95ea984620d7.tar.gz
rails-9cfeefb637b603ce41d3019c8baa95ea984620d7.tar.bz2
rails-9cfeefb637b603ce41d3019c8baa95ea984620d7.zip
Reorganized initializers a bit to enable better hooks for common cases without the need for Railtie. Specifically, the following hooks were added:
* before_configuration: this hook is run immediately after the Application class comes into existence, but before the user has added any configuration. This is the appropriate place to set configuration for your plugin * before_initialize: This is run after all of the user's configuration has completed, but before any initializers have begun (in other words, it runs right after config/environments/{development,production,test}.rb) * after_initialize: This is run after all of the initializers have run. It is an appropriate place for forking in a preforking setup Each of these hooks may be used via ActiveSupport.on_load(name) { }. In all these cases, the context inside the block will be the Application object. This means that for simple cases, you can use these hooks without needing to create a Railtie.
Diffstat (limited to 'railties/lib/rails/application')
-rw-r--r--railties/lib/rails/application/bootstrap.rb8
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/lib/rails/application/finisher.rb6
3 files changed, 7 insertions, 9 deletions
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index 022e1a91d8..e62eed8a87 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -10,7 +10,8 @@ module Rails
require environment if environment
end
- initializer :load_all_active_support do
+ initializer :load_active_support do
+ require 'active_support/dependencies'
require "active_support/all" unless config.active_support.bare
end
@@ -18,7 +19,6 @@ module Rails
# Used by Passenger to ensure everything's loaded before forking and
# to avoid autoload race conditions in JRuby.
initializer :preload_frameworks do
- require 'active_support/dependencies'
ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks
end
@@ -66,8 +66,8 @@ module Rails
ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load
end
- initializer :bootstrap_load_path do
- # This is just an initializer used as hook so all load paths are loaded together
+ initializer :bootstrap_hook do |app|
+ ActiveSupport.run_load_hooks(:before_initialize, app)
end
end
end
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 1ad77fdfec..cd77f1adaf 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -33,7 +33,7 @@ module Rails
end
def middleware
- @middleware ||= default_middleware_stack
+ @middleware ||= app_middleware.merge_into(default_middleware_stack)
end
def metal_loader
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index 94507bb387..03bc270c81 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -35,10 +35,8 @@ module Rails
app
end
- initializer :after_initialize do
- config.after_initialize_blocks.each do |block|
- block.call(self)
- end
+ initializer :finisher_hook do |app|
+ ActiveSupport.run_load_hooks(:after_initialize, app)
end
# Disable dependency loading during request cycle