From c1b4a5eb564f8fdd71307efeb5ee729cc6f20059 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 14 Apr 2009 16:21:06 -0500 Subject: Make dispatcher instances immutable --- .../lib/action_controller/dispatch/dispatcher.rb | 22 +++++++++------------- actionpack/test/controller/dispatcher_test.rb | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/actionpack/lib/action_controller/dispatch/dispatcher.rb b/actionpack/lib/action_controller/dispatch/dispatcher.rb index 1a923724a1..8ed7de4788 100644 --- a/actionpack/lib/action_controller/dispatch/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatch/dispatcher.rb @@ -66,16 +66,21 @@ module ActionController define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch def initialize - @app = @@middleware.build(lambda { |env| self.dup._call(env) }) + @app = @@middleware.build(lambda { |env| self._call(env) }) + freeze end - def dispatch + def call(env) + @app.call(env) + end + + def _call(env) begin run_callbacks :before_dispatch - Routing::Routes.call(@env) + Routing::Routes.call(env) rescue Exception => exception if controller ||= (::ApplicationController rescue Base) - controller.call_with_exception(@env, exception).to_a + controller.call_with_exception(env, exception).to_a else raise exception end @@ -84,15 +89,6 @@ module ActionController end end - def call(env) - @app.call(env) - end - - def _call(env) - @env = env - dispatch - end - def flush_logger Base.logger.flush end diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb index 031a10975d..721bcf6136 100644 --- a/actionpack/test/controller/dispatcher_test.rb +++ b/actionpack/test/controller/dispatcher_test.rb @@ -46,7 +46,7 @@ class DispatcherTest < Test::Unit::TestCase end def test_failsafe_response - Dispatcher.any_instance.expects(:dispatch).raises('b00m') + Dispatcher.any_instance.expects(:_call).raises('b00m') ActionDispatch::Failsafe.any_instance.expects(:log_failsafe_exception) assert_nothing_raised do -- cgit v1.2.3