[Ruby-session-devel-cvs] CVS: ruby-session/src session.rb,NONE,1.1
Status: Alpha
Brought to you by:
thetitan
From: Sean C. <the...@us...> - 2002-06-13 12:28:29
|
Update of /cvsroot/ruby-session/ruby-session/src In directory usw-pr-cvs1:/tmp/cvs-serv28716 Added Files: session.rb Log Message: *) Checking in work *) Still an outstanding DBI bug with unescaping data on restore from the database *) Oustanding bug with converting to a Time object from data stored in a 'timestamp without time zone' data type --- NEW FILE: session.rb --- #!/usr/local/bin/ruby -w # # See the LICENSE file for copyright and distribution information. # # $Id: session.rb,v 1.1 2002/06/13 12:28:25 thetitan Exp $ require 'digest/md5' class Session @@commit = [] @@init = [] @@load = [] public def Session.generate() md5digest = Digest::MD5.new() md5digest.update(Time.now.to_f.to_s + rand.to_s + $$.to_s) return(md5digest.hexdigest) end # def Session.generate def [](key) return(@data[key]) end # def [] def []=(key, value) return(@data[key] = value) end # def []= def commit(*args) @session_id = Session.generate() if @session_id.nil? for commit_meth in @@commit m = self.method(commit_meth) m.call(*args) end # for commit_meth end # def commit() def load(*args) raise "Need a Session ID" if @session_id.nil? for load_meth in @@load m = self.method(load_meth) m.call(*args) end # for load_meth end # def load() def reset() @active = true @data = {} @expiration_time = nil @last_updated = Time.now() @old_session_id = nil @rekey_time = nil @start_date = Time.now() @secure = false @session_id = nil @session_data = nil end # def reset() def session_id() @session_id = Session.generate() if @session_id.nil? return(@session_id) end # def session_id() def session_id=(session_id) raise "SessionID already set" if !@session_id.nil? return(@session_id = session_id) end private def initialize(*args) reset() $session = self for init_meth in @@init m = self.method(init_meth) m.call(*args) end # for commit_meth end # def initialize end # class Session |