[Ruby-session-devel-cvs] CVS: ruby-session/src/apache session.rb,1.1,1.2
Status: Alpha
Brought to you by:
thetitan
From: Sean C. <the...@us...> - 2001-08-25 19:57:34
|
Update of /cvsroot/ruby-session/ruby-session/src/apache In directory usw-pr-cvs1:/tmp/cvs-serv29654/src/apache Modified Files: session.rb Log Message: Added more functionality... created an abstract front end to various persistence layers Fixd speling erors Index: session.rb =================================================================== RCS file: /cvsroot/ruby-session/ruby-session/src/apache/session.rb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- session.rb 2001/08/25 10:31:52 1.1 +++ session.rb 2001/08/25 19:57:31 1.2 @@ -1,6 +1,6 @@ #!/usr/local/bin/ruby -w -# ruby-session: Got persistance? +# ruby-session: Got persistence? # Copyright 2001 # Sean Chittenden <se...@ch...>. All rights reserved. @@ -14,10 +14,10 @@ # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: +# must display the following acknowledgment: # # This product includes software developed by Sean Chittenden -# <se...@ch...> and ruby-tmpl's contributors. +# <se...@ch...> and ruby-session's contributors. # # 4. Neither the name of the software nor the names of its contributors # may be used to endorse or promote products derived from this software @@ -51,18 +51,35 @@ def [] (key) return(@data[key]) end + # End: def [] () def []= (key, value) return(@data[key] = value) end + # End: def []= () def delete () - self.make_location unless(@location) - self._delete() + @location = self.make_location unless(@location) + self._delete end + # End: def delete () + + def Session.exist? (location) + return(Session._exist?(location)) + end + # End: def Session.exist? () + + + def exist? (session_id) + @location = self.make_location unless (@location) + return(self._exist?) + end + # End: def exist? () + + def generate () require 'digest/md5' md5digest = Digest::MD5.new @@ -70,25 +87,37 @@ @session_id = md5digest.hexdigest return(@session_id) end + # End: def generate () + def Session.make_location (*args) + begin + return(Session._make_location(args)) + rescue NameError + raise RuntimeError, "No Session persistence layers available" + end + end + # End: def Session.make_location () + + def persist () - self.make_location() unless(@location) + @location = self.make_location unless(@location) @data['__ruby_session_expired__'] = (@expired ? 'y' : 'n') @data['__ruby_session_start_time__'] = @start_time.to_f.to_s - self._persist() + self._persist @data.delete('__ruby_session_expired__') @data.delete('__ruby_session_start_time__') end + # End: def persist () def restore () - self.make_location() unless(@location) + @location = self.make_location unless(@location) - self._restore() + self._restore @expired = (@data.delete('__ruby_session_expired__') == 'y' ? true : false) @start_time = Time.at(@data.delete('__ruby_session_start_time__').to_f) @@ -104,10 +133,12 @@ raise LoadError, "Invalid Session Type '#{type}'" end end + # End: def type= () private + def initialize (options = {}) @data = (options.has_key?('session_data') ? options['session_data'] : {}) @expired = false @@ -121,7 +152,7 @@ if options.has_key?('session_id') @session_id = options['session_id'] - self.restore() + self.restore else @session_id = self.generate end |