Sha256: 0dfbbbbc8df746d107a64703d52d4fb79b6d0f72a36cb7bd15ce49b9403bf58a

Contents?: true

Size: 1.62 KB

Versions: 8

Compression:

Stored size: 1.62 KB

Contents

require File.join(File.dirname(__FILE__), "base")
module Mack
  module RunnerHelpers # :nodoc:
    class Session < Mack::RunnerHelpers::Base
      
      attr_accessor :sess_id
      
      def start(request, response, cookies)
        if configatron.mack.use_sessions
          self.sess_id = retrieve_session_id(request, response, cookies)
          unless self.sess_id
            self.sess_id = create_new_session(request, response, cookies)
          else
            sess = Mack::SessionStore.get(self.sess_id, request, response, cookies)
            if sess
              request.session = sess
            else
              # we couldn't find it in the store, so we need to create it:
              self.sess_id = create_new_session(request, response, cookies)
            end
          end
        end
      end
      
      def complete(request, response, cookies)
        if configatron.mack.use_sessions
          unless response.redirection?
            request.session.delete(:tell)
          end
          Mack::SessionStore.set(request.session.id, request, response, cookies)
        end
      end
      
      private
      def retrieve_session_id(request, response, cookies)
        cookies[configatron.mack.session_id]
      end
      
      def create_new_session(request, response, cookies)
        id = String.randomize(40).downcase
        cookies[configatron.mack.session_id] = {:value => id, :expires => nil}
        sess = Mack::Session.new(id)
        request.session = sess
        Mack::SessionStore.set(request.session.id, request, response, cookies)
        id
      end
      
    end # Session
  end # RunnerHelpers
end # Mack

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mack-0.8.0.100 lib/mack/runner_helpers/session.rb
mack-0.8.0.101 lib/mack/runner_helpers/session.rb
mack-0.8.0 lib/mack/runner_helpers/session.rb
mack-0.8.1 lib/mack/runner_helpers/session.rb
mack-0.8.2 lib/mack/runner_helpers/session.rb
mack-0.8.0.2 lib/mack/runner_helpers/session.rb
mack-0.8.3 lib/mack/runner_helpers/session.rb
mack-0.8.3.1 lib/mack/runner_helpers/session.rb