Class: Maveric::SimpleSessions::Session
- Inherits:
-
Object
- Object
- Maveric::SimpleSessions::Session
- Defined in:
- lib/maveric/sessions.rb
Overview
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.
Constant Summary collapse
- DURATION =
15*60
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
Instance Method Summary collapse
-
#<=>(obj) ⇒ Object
One session is less than another if it expires sooner.
-
#id ⇒ Object
Returns an upcased hexed object_id, not #object_id.to_s(16) however.
-
#initialize(duration = DURATION) ⇒ Session
constructor
The default session length is 15 minutes.
-
#to_s(env = nil) ⇒ Object
Perhaps better named as #to_cookie for clarity?.
-
#touch ⇒ Object
Set this session’s expiry to @duration+Time.now.
Constructor Details
#initialize(duration = DURATION) ⇒ Session
The default session length is 15 minutes. Simple to change.
39 40 41 42 |
# File 'lib/maveric/sessions.rb', line 39 def initialize duration=DURATION @duration, @data = duration, {} touch end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
44 45 46 |
# File 'lib/maveric/sessions.rb', line 44 def data @data end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
44 45 46 |
# File 'lib/maveric/sessions.rb', line 44 def duration @duration end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
44 45 46 |
# File 'lib/maveric/sessions.rb', line 44 def expires @expires end |
Instance Method Details
#<=>(obj) ⇒ Object
One session is less than another if it expires sooner. Useful if we are managing in a manner akin to a priority stack.
54 55 56 57 58 |
# File 'lib/maveric/sessions.rb', line 54 def <=> obj Session === obj ? self.expires <=> obj.expires : super end |
#id ⇒ Object
Returns an upcased hexed object_id, not #object_id.to_s(16) however.
47 48 49 |
# File 'lib/maveric/sessions.rb', line 47 def id @id||=[object_id<<1].pack('i').unpack('I')[0].to_s(16).upcase end |
#to_s(env = nil) ⇒ Object
Perhaps better named as #to_cookie for clarity?
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/maveric/sessions.rb', line 66 def to_s env=nil touch c = "#{::Maveric::SimpleSessions::COOKIE_NAME}=#{id}" #required c << "; expires=#{expires.httpdate}" return c unless env c << "; domain=#{env['SERVER_NAME']};" # need to determine a good way to discern proper path. # pertinant Maveric? c << "; secure" if false c end |
#touch ⇒ Object
Set this session’s expiry to @duration+Time.now
61 62 63 |
# File 'lib/maveric/sessions.rb', line 61 def touch @expires = Time.now.gmtime + Integer(@duration) end |