aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/engine.rb
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/engine.rb
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/engine.rb')
-rw-r--r--railties/lib/rails/engine.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index ab0ead65a9..652bd40ee4 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -45,7 +45,7 @@ module Rails
# app.middleware.use MyEngine::Middleware
# end
# end
- #
+ #
# == Paths
#
# Since Rails 3.0, both your Application and Engines do not have hardcoded paths.
@@ -125,7 +125,7 @@ module Rails
end
end
- delegate :middleware, :paths, :root, :to => :config
+ delegate :paths, :root, :to => :config
def load_tasks
super
@@ -133,7 +133,7 @@ module Rails
end
# Add configured load paths to ruby load paths and remove duplicates.
- initializer :set_load_path, :before => :bootstrap_load_path do
+ initializer :set_load_path, :before => :bootstrap_hook do
config.load_paths.reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
@@ -142,7 +142,10 @@ module Rails
# Set the paths from which Rails will automatically load source files,
# and the load_once paths.
- initializer :set_autoload_paths, :before => :bootstrap_load_path do |app|
+ #
+ # This needs to be an initializer, since it needs to run once
+ # per engine and get the engine as a block parameter
+ initializer :set_autoload_paths, :before => :bootstrap_hook do |app|
ActiveSupport::Dependencies.load_paths.unshift(*config.load_paths)
if reloadable?(app)
@@ -200,7 +203,9 @@ module Rails
end
end
- initializer :load_app_classes do |app|
+ # This needs to be an initializer, since it needs to run once
+ # per engine and get the engine as a block parameter
+ initializer :load_app_classes, :before => :finisher_hook do |app|
next if $rails_rake_task
if app.config.cache_classes