<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/runner_helpers/base.rb</filename>
    </added>
    <added>
      <filename>lib/runner_helpers/registry.rb</filename>
    </added>
    <added>
      <filename>lib/runner_helpers/request_logger.rb</filename>
    </added>
    <added>
      <filename>lib/runner_helpers/session.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -43,6 +43,7 @@ module Mack
 
     # Gives access to the session. See Mack::Session for more information.
     def session
+      raise Mack::Errors::NoSessionError.new if self.request.session.nil?
       self.request.session
     end
 
@@ -364,26 +365,12 @@ module Mack
     # Make sure that all the class level methods got included into the receiver's class
     #
     def self.included(base)
-      Mack::Controller::Registry.instance.controllers &lt;&lt; base
+      Mack::Controller::Registry.add(base)
       base.extend(ClassMethods)
     end
     
     # Houses a repository of all the controllers in the system.
-    class Registry
-      include Singleton
-      
-      attr_reader :controllers
-      
-      def initialize
-        @controllers = []
-      end
-      
-      # Add a controller to the registry.
-      def self.add(controller)
-        Mack::Controller::Registry.instance.controllers &lt;&lt; controller
-        Mack::Controller::Registry.instance.controllers.uniq!
-      end
-      
+    class Registry &lt; Mack::Utils::Registry
     end
     
   end # Controller</diff>
      <filename>lib/controller/controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,10 @@
 module Mack
   module Errors # :nodoc:
     
+    # Raised when there is no session available and one is trying to be accessed.
+    class NoSessionError &lt; StandardError
+    end
+    
     # Raised when someone calls render twice in one action
     # 
     # Example:</diff>
      <filename>lib/errors/errors.rb</filename>
    </modified>
    <modified>
      <diff>@@ -61,6 +61,7 @@ module Mack
         &quot;mack::cache_classes&quot; =&gt; true,
         &quot;mack::use_lint&quot; =&gt; true,
         &quot;mack::show_exceptions&quot; =&gt; true,
+        &quot;mack::use_sessions&quot; =&gt; true,
         &quot;mack::session_id&quot; =&gt; &quot;_mack_session_id&quot;,
         &quot;mack::rendering_systems&quot; =&gt; [:action, :text, :partial, :public, :url, :xml],
         &quot;mack::cookie_values&quot; =&gt; {</diff>
      <filename>lib/initialization/configuration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,7 +35,7 @@ unless Mack::Configuration.initialized
 
   Mack.logger.info &quot;Initializing core classes...&quot;
   # Require all the necessary files to make Mack actually work!
-  lib_dirs = [&quot;errors&quot;, &quot;core_extensions&quot;, &quot;utils&quot;, &quot;routing&quot;, &quot;view_helpers&quot;, &quot;rendering&quot;, &quot;controller&quot;, &quot;tasks&quot;, &quot;initialization/server&quot;, &quot;generators&quot;, &quot;distributed&quot;]
+  lib_dirs = [&quot;errors&quot;, &quot;core_extensions&quot;, &quot;utils&quot;, &quot;runner_helpers&quot;, &quot;routing&quot;, &quot;view_helpers&quot;, &quot;rendering&quot;, &quot;controller&quot;, &quot;tasks&quot;, &quot;initialization/server&quot;, &quot;generators&quot;, &quot;distributed&quot;]
   lib_dirs &lt;&lt; &quot;testing&quot; if Mack.env == &quot;test&quot;
   lib_dirs.each do |dir|
     dir_globs = Dir.glob(File.join(fl, dir, &quot;**/*.rb&quot;))</diff>
      <filename>lib/mack.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,51 +9,44 @@ module Mack
     attr_reader :response # :nodoc:
     attr_reader :request # :nodoc:
     attr_reader :cookies # :nodoc:
+    attr_reader :runner_helpers # :nodoc:
+    
     # This method needs to be defined as part of the Rack framework. As is noted for the Mack::Runner
     # class, this is where the center of the Mack framework lies.
     def call(env)
-      # pp env
       begin
-        setup(env) do
-          begin
-            route = Mack::Routes::RouteMap.instance.get_route_from_request(self.request)
-            if route[:redirect_to]
-              # because the route is specified to be a redirect, let's do that:
-              redirect_to(route)
-            else
-              self.request.all_params[:original_controller] = route[:controller]
-              self.request.all_params[:original_action] = route[:action]
-              run_controller(route)
-            end
-          # rescue Mack::Errors::ResourceNotFound, Mack::Errors::UndefinedRoute =&gt; e
-          #   return try_to_find_resource(env, e)
-          rescue Exception =&gt; e
-            route = Mack::Routes::RouteMap.instance.get_route_from_error(e.class)
-            unless route.nil?
-              run_controller(route, e)
+        setup(env)
+        begin
+          route = Mack::Routes::RouteMap.instance.get_route_from_request(self.request)
+          if route[:redirect_to]
+            # because the route is specified to be a redirect, let's do that:
+            redirect_to(route)
+          else
+            self.request.all_params[:original_controller] = route[:controller]
+            self.request.all_params[:original_action] = route[:action]
+            run_controller(route)
+          end
+        # rescue Mack::Errors::ResourceNotFound, Mack::Errors::UndefinedRoute =&gt; e
+        #   return try_to_find_resource(env, e)
+        rescue Exception =&gt; e
+          route = Mack::Routes::RouteMap.instance.get_route_from_error(e.class)
+          unless route.nil?
+            run_controller(route, e)
+          else
+            if e.class == Mack::Errors::ResourceNotFound || e.class == Mack::Errors::UndefinedRoute
+              return try_to_find_resource(env, e)
             else
-              if e.class == Mack::Errors::ResourceNotFound || e.class == Mack::Errors::UndefinedRoute
-                return try_to_find_resource(env, e)
-              else
-                raise e
-              end
+              raise e
             end
           end
-        end # setup
+        end
+        teardown
       rescue Exception =&gt; e
         Mack.logger.error(e)
         raise e
       end
     end
     
-    #--
-    # This method gets called after the session has been established. Override this method
-    # to add custom code around requests.
-    # def custom_dispatch_wrapper
-    #   yield
-    # end
-    #++
-    
     #private
     def run_controller(route, e = nil)
       # let's handle a normal request:
@@ -75,71 +68,25 @@ module Mack
       self.response.write(c.run)
     end
     
-    def log_request
-      s_time = Time.now
-      x = yield
-      e_time = Time.now
-      p_time = e_time - s_time
-      if app_config.log.detailed_requests
-        msg = &quot;\n\t[#{@request.request_method.upcase}] '#{@request.path_info}'\n&quot;
-        msg &lt;&lt; &quot;\tSession ID: #{@request.session.id}\n&quot;
-        msg &lt;&lt; &quot;\tParameters: #{@request.all_params}\n&quot;
-        msg &lt;&lt; &quot;\tCompleted in #{p_time} (#{(1 / p_time).round} reqs/sec) | #{@response.status} [#{@request.full_host}]&quot;
-      else
-        msg = &quot;[#{@request.request_method.upcase}] '#{@request.path_info}' (#{p_time})&quot;
-      end
-      Mack.logger.info(msg)
-      x
-    end
-    
     # Setup the request, response, cookies, session, etc...
     # yield up, and then clean things up afterwards.
     def setup(env)
-      exception = nil
-      log_request do
-        @request = Mack::Request.new(env) 
-        @response = Mack::Response.new
-        @cookies = Mack::CookieJar.new(self.request, self.response)
-        session do
-          begin
-            # custom_dispatch_wrapper do
-              yield
-            # end
-          rescue Exception =&gt; e
-            exception = e
-          end
-        end
+      @request = Mack::Request.new(env) 
+      @response = Mack::Response.new
+      @cookies = Mack::CookieJar.new(self.request, self.response)
+      @runner_helpers = []
+      Mack::RunnerHelpers::Registry.registered_items.each do |helper|
+        help = helper.new
+        help.start(self.request, self.response, self.cookies)
+        @runner_helpers &lt;&lt; help
       end
-      raise exception if exception
-      self.response.finish
     end
     
-    def session
-      sess_id = self.cookies[app_config.mack.session_id]
-      unless sess_id
-        sess_id = create_new_session
-      else
-        sess = Cachetastic::Caches::MackSessionCache.get(sess_id)
-        if sess
-          self.request.session = sess
-        else
-          # we couldn't find it in the store, so we need to create it:
-          sess_id = create_new_session
-        end
+    def teardown
+      self.runner_helpers.reverse.each do |help|
+        help.complete(self.request, self.response, self.cookies)
       end
-
-      yield
-      
-      Cachetastic::Caches::MackSessionCache.set(sess_id, self.request.session)
-    end
-    
-    def create_new_session
-      id = String.randomize(40).downcase
-      self.cookies[app_config.mack.session_id] = {:value =&gt; id, :expires =&gt; nil}
-      sess = Mack::Session.new(id)
-      self.request.session = sess
-      Cachetastic::Caches::MackSessionCache.set(id, sess)
-      id
+      self.response.finish
     end
     
     def try_to_find_resource(env, exception)</diff>
      <filename>lib/runner.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,10 @@
 module Mack
   module Utils
+    
+    # Houses a registry of Rack runners that should be called before the Mack::Runner.
+    class RunnersRegistry &lt; Mack::Utils::Registry
+    end
+    
     module Server
     
       # This method wraps all the necessary components of the Rack system around
@@ -8,9 +13,8 @@ module Mack
         # Mack framework:
         app = Mack::Runner.new
         
-        Mack::Utils::Server::Registry.instance.wrappers do |w|
-          puts &quot;Wrapping app with: #{w}&quot;
-          app = w.new(app)
+        Mack::Utils::RunnersRegistry.registered_items.each do |runner|
+          app = runner.new(app)
         end
         
         # Any urls listed will go straight to the public directly and will not be served up via the app:
@@ -21,28 +25,9 @@ module Mack
         app = Rack::Recursive.new(app)
         # This will reload any edited classes if the cache_classes config setting is set to true.
         app = Rack::Reloader.new(app, 1) unless app_config.mack.cache_classes
-        # TODO: Not sure about this logger, investigate better ones.
-        # TODO: Depends on Mack.logger already being configured.
-        # This makes it a drag run this 'standalone' in another Ruby program.
-        # app = Rack::CommonLogger.new(app, Mack.logger)
         app
       end
       
-      class Registry
-        include Singleton
-        
-        attr_reader :wrappers
-        
-        def initialize
-          @wrappers = []
-        end
-        
-        def add(klass)
-          @wrappers &lt;&lt; klass
-        end
-        
-      end
-    
     end # Server
   end # Utils
 end # Mack
\ No newline at end of file</diff>
      <filename>lib/utils/server.rb</filename>
    </modified>
    <modified>
      <diff>@@ -35,9 +35,9 @@ describe Mack::Controller do
     it &quot;should hold a list of all the controllers registered with Mack&quot; do
       class RegTestController
       end
-      Mack::Controller::Registry.instance.controllers.should_not include(RegTestController)
+      Mack::Controller::Registry.registered_items.should_not include(RegTestController)
       RegTestController.send(:include, Mack::Controller)
-      Mack::Controller::Registry.instance.controllers.should include(RegTestController)
+      Mack::Controller::Registry.registered_items.should include(RegTestController)
     end
     
   end</diff>
      <filename>test/unit/controller/controller_base_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,4 +14,33 @@ describe Mack::Session do
     
   end
   
+  describe &quot;app_config.mack.use_sessions&quot; do
+    
+    class SessionSpecController
+      include Mack::Controller
+      
+      def index
+        session[:id] = params[:id] if session[:id].nil?
+        render(:text, &quot;id: #{session[:id]}&quot;)
+      end
+      
+    end
+    
+    it &quot;should be able to turn off sessions&quot; do
+      temp_app_config(&quot;mack::use_sessions&quot; =&gt; false) do
+        lambda{get &quot;/session_spec/index&quot;}.should raise_error(Mack::Errors::NoSessionError)
+      end
+    end
+    
+    it &quot;should be able to turn on sessions (default)&quot; do
+      get &quot;/session_spec/index?id=1&quot;
+      response.body.should match(/id: 1/)
+      get &quot;/session_spec/index&quot;
+      response.body.should match(/id: 1/)
+      get &quot;/session_spec/index?id=2&quot;
+      response.body.should match(/id: 1/)
+    end
+    
+  end
+  
 end
\ No newline at end of file</diff>
      <filename>test/unit/controller/session_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>0ee488dc7d49125394c853f950263513263fb88a</id>
    </parent>
    <parent>
      <id>d32c0c6a97cc93a0649488f071f7e6bc287da723</id>
    </parent>
  </parents>
  <author>
    <name>dsutedja</name>
    <email>dsutedja@helium.com</email>
  </author>
  <url>http://github.com/markbates/mack/commit/6455ed89edd2f9179f0fb0e806901ad82af474c3</url>
  <id>6455ed89edd2f9179f0fb0e806901ad82af474c3</id>
  <committed-date>2008-07-22T07:31:33-07:00</committed-date>
  <authored-date>2008-07-22T07:31:33-07:00</authored-date>
  <message>Merge branch 'master' of git@github.com:markbates/mack

Conflicts:

	CHANGELOG</message>
  <tree>9964e2749d57526a3680da616d85706b3ce52de3</tree>
  <committer>
    <name>dsutedja</name>
    <email>dsutedja@helium.com</email>
  </committer>
</commit>
