Class: Maveric::SimpleSessions

Inherits:
Set
  • Object
show all
Defined in:
lib/maveric/sessions.rb

Overview

Contains session data and provides conveniance in generating an appropriate cookie.

This is a simple session implementation. Data is kept in a self maintaining Set persisting in memory. Noot good if yoou’re dealing with oodles of sets.

Defined Under Namespace

Classes: Session

Constant Summary collapse

'SESSIONID'

Instance Method Summary collapse

Instance Method Details

#session(id) ⇒ Object

Looks up a sessions by id given. The id argument should be a string of a hex number. (num.to_s(16) If id is not found a new Session is created and its Session#id is returned.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/maveric/sessions.rb', line 17

def session id #wants stringed hex num

  #ensure crusty old sessions don't linger
  @__i = 0 unless defined? @__i
  @__i += 1
  reject!{|s| s.expires < Time.now-3 } if (@__i%=10) == 0 # 3 second grace
  
  if id # now get the session if we have something to search for
    session = find{|s| id.casecmp(s.id)==0 }
  else # there isn't one? then make a new one!
    add session=Session.new
  end
  return session
end