Class Maveric::Sessions::Session
In: maveric/sessions.rb
Parent: Object

Because apparently sessions are handy or helpful or something like that. Implemented as that the hex of their #object_id (the one you‘d see in an Object#inspect) is treated as a session id.

Methods

<=>   id   new   to_s   touch  

Constants

DURATION = 15*60

Attributes

data  [R] 
duration  [R] 
expires  [R] 

Public Class methods

The default session length is 15 minutes. Simple to change.

[Source]

    # File maveric/sessions.rb, line 25
25:       def initialize duration=DURATION
26:         ::Maveric.type_check :duration, duration, Integer
27:         @duration, @data = duration, {}
28:         touch
29:         ::Maveric.log.debug self
30:       end

Public Instance methods

One session is less than another if it expires sooner. Useful if we are managing in a manner akin to a priority stack.

[Source]

    # File maveric/sessions.rb, line 37
37:       def <=> obj; Session === obj ? self.expires <=> obj.expires : super; end

Returns an upcased hexed object_id, not #object_id.to_s(16) however.

[Source]

    # File maveric/sessions.rb, line 33
33:       def id; @id||=[object_id<<1].pack('i').unpack('I')[0].to_s(16).upcase; end

Perhaps better named as #to_cookie for clarity?

[Source]

    # File maveric/sessions.rb, line 41
41:       def to_s env=nil
42:         touch
43:         c = "#{::Maveric::Sessions::COOKIE_NAME}=#{id}" #required
44:         c << "; expires=#{expires.httpdate}"
45:         return c unless env
46:         c << "; domain=#{env['SERVER_NAME']};"
47:         # need to determine a good way to discern proper path.
48:         # pertinant Maveric?
49:         c << "; secure" if false
50:         c
51:       end

Set this session‘s expiry to @duration+Time.now

[Source]

    # File maveric/sessions.rb, line 39
39:       def touch; @expires = Time.now.gmtime + Integer(@duration); end

[Validate]