Class: Maveric::Sessions::Session
- Inherits:
-
Object
- Object
- Maveric::Sessions::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.
25 26 27 28 29 30 |
# File 'lib/maveric/sessions.rb', line 25 def initialize duration=DURATION ::Maveric.type_check :duration, duration, Integer @duration, @data = duration, {} touch ::Maveric.log.debug self end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
31 32 33 |
# File 'lib/maveric/sessions.rb', line 31 def data @data end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
31 32 33 |
# File 'lib/maveric/sessions.rb', line 31 def duration @duration end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
31 32 33 |
# File 'lib/maveric/sessions.rb', line 31 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.
37 |
# File 'lib/maveric/sessions.rb', line 37 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.
33 |
# File 'lib/maveric/sessions.rb', line 33 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?
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/maveric/sessions.rb', line 41 def to_s env=nil touch c = "#{::Maveric::Sessions::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
39 |
# File 'lib/maveric/sessions.rb', line 39 def touch; @expires = Time.now.gmtime + Integer(@duration); end |