diff options
author | Joshua Peek <josh@joshpeek.com> | 2009-05-03 09:41:40 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-05-03 09:41:40 -0500 |
commit | bcc4537f2a0d37fc02d67e9564fa5c9c5555b3d5 (patch) | |
tree | 2084bb22890f635239564b508297aa246cfb591a /actionpack/lib/action_controller/dispatch | |
parent | e0660192806fc1ec8b75654e69211f85c9f1256b (diff) | |
download | rails-bcc4537f2a0d37fc02d67e9564fa5c9c5555b3d5.tar.gz rails-bcc4537f2a0d37fc02d67e9564fa5c9c5555b3d5.tar.bz2 rails-bcc4537f2a0d37fc02d67e9564fa5c9c5555b3d5.zip |
Wrap dispatcher callbacks around the whole middleware chain. Kill unnecessary Reloader middleware.
Diffstat (limited to 'actionpack/lib/action_controller/dispatch')
-rw-r--r-- | actionpack/lib/action_controller/dispatch/dispatcher.rb | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/actionpack/lib/action_controller/dispatch/dispatcher.rb b/actionpack/lib/action_controller/dispatch/dispatcher.rb index c0eb359547..cce3b6175d 100644 --- a/actionpack/lib/action_controller/dispatch/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatch/dispatcher.rb @@ -5,9 +5,9 @@ module ActionController class << self def define_dispatcher_callbacks(cache_classes) unless cache_classes - unless self.middleware.include?(ActionDispatch::Reloader) - self.middleware.insert_after(ActionDispatch::Failsafe, ActionDispatch::Reloader) - end + # Development mode callbacks + before_dispatch :reload_application + after_dispatch :cleanup_application ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false end @@ -40,22 +40,11 @@ module ActionController def run_prepare_callbacks new.send :run_callbacks, :prepare_dispatch end - - def reload_application - # Run prepare callbacks before every request in development mode - run_prepare_callbacks - - Routing::Routes.reload - end - - def cleanup_application - # Cleanup the application before processing the current request. - ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord) - ActiveSupport::Dependencies.clear - ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord) - end end + cattr_accessor :router + self.router = Routing::Routes + cattr_accessor :middleware self.middleware = ActionDispatch::MiddlewareStack.new do |middleware| middlewares = File.join(File.dirname(__FILE__), "middlewares.rb") @@ -66,21 +55,31 @@ module ActionController define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch def initialize - @app = @@middleware.build(lambda { |env| self._call(env) }) + @app = @@middleware.build(@@router) freeze end def call(env) - @app.call(env) - end - - def _call(env) run_callbacks :before_dispatch - Routing::Routes.call(env) + @app.call(env) ensure run_callbacks :after_dispatch, :enumerator => :reverse_each end + def reload_application + # Run prepare callbacks before every request in development mode + run_callbacks :prepare_dispatch + + @@router.reload + end + + def cleanup_application + # Cleanup the application before processing the current request. + ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord) + ActiveSupport::Dependencies.clear + ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord) + end + def flush_logger Base.logger.flush end |