aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/railtie/configuration.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/railtie/configuration.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/railtie/configuration.rb')
-rw-r--r--railties/lib/rails/railtie/configuration.rb48
1 files changed, 42 insertions, 6 deletions
diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb
index 16eccaccc4..f57d82a3d8 100644
--- a/railties/lib/rails/railtie/configuration.rb
+++ b/railties/lib/rails/railtie/configuration.rb
@@ -3,10 +3,50 @@ require 'rails/configuration'
module Rails
class Railtie
class Configuration
+ class MiddlewareStackProxy
+ def initialize
+ @operations = []
+ end
+
+ def insert_before(*args, &block)
+ @operations << [:insert_before, args, block]
+ end
+
+ alias insert insert_before
+
+ def insert_after(*args, &block)
+ @operations << [:insert_after, args, block]
+ end
+
+ def swap(*args, &block)
+ @operations << [:swap, args, block]
+ end
+
+ def use(*args, &block)
+ @operations << [:use, args, block]
+ end
+
+ def merge_into(other)
+ @operations.each do |operation, args, block|
+ other.send(operation, *args, &block)
+ end
+ other
+ end
+ end
+
def initialize
@@options ||= {}
end
+ # This allows you to modify the application's middlewares from Engines.
+ #
+ # All operations you run on the app_middleware will be replayed on the
+ # application once it is defined and the default_middlewares are
+ # created
+ def app_middleware
+ @@app_middleware ||= MiddlewareStackProxy.new
+ end
+
# Holds generators configuration:
#
# config.generators do |g|
@@ -28,12 +68,8 @@ module Rails
end
end
- def after_initialize_blocks
- @@after_initialize_blocks ||= []
- end
-
- def after_initialize(&blk)
- after_initialize_blocks << blk if blk
+ def after_initialize(&block)
+ ActiveSupport.on_load(:after_initialize, :yield => true, &block)
end
def to_prepare_blocks