lib/innate/session.rb in innate-2009.04.12 vs lib/innate/session.rb in innate-2009.05

- old
+ new

@@ -7,16 +7,16 @@ # will be persisted completely into the cache, no question asked. # # You may store anything in here that you may also store in the corresponding # store, usually it's best to keep it to things that are safe to Marshal. # - # The default time of expiration is * - # + # The default time of expiration is: # Time.at(2147483647) # => Tue Jan 19 12:14:07 +0900 2038 # # Hopefully we all have 64bit systems by then. - + # + # The Session instance is compatible with the specification of rack.session. class Session include Optioned options.dsl do o "Key for the session cookie", @@ -38,52 +38,54 @@ @cookie_set = false @cache_sid = nil @flash = Flash.new(self) end - def []=(key, value) + # Rack interface + + def store(key, value) cache_sid[key] = value end + alias []= store - def [](key) + def fetch(key, value = nil) cache_sid[key] end + alias [] fetch def delete(key) cache_sid.delete(key) end def clear cache.delete(sid) @cache_sid = nil end - def cache_sid - @cache_sid ||= cache[sid] || {} - end + # Additional interface def flush(response = @response) return if !@cache_sid or @cache_sid.empty? flash.rotate! ttl = (Time.at(cookie_value[:expires]) - Time.now).to_i cache.store(sid, cache_sid, :ttl => ttl) set_cookie(response) end + private + + def cache_sid + @cache_sid ||= cache[sid] || {} + end + def sid @sid ||= cookie || generate_sid end def cookie @request.cookies[options.key] end - - def inspect - cache.inspect - end - - private def cache Innate::Cache.session end