lib/plezi/handlers/session.rb in plezi-0.12.2 vs lib/plezi/handlers/session.rb in plezi-0.12.3
- old
+ new
@@ -23,10 +23,14 @@
if id && (conn=Plezi.redis)
return self
end
failed
end
+ # returns the session id (the session cookie value).
+ def id
+ @id
+ end
# Get a key from the session data store. If a Redis server is supplied, it will be used to synchronize session data.
#
# Due to scaling considirations, all keys will be converted to strings, so that `"name" == :name` and `1234 == "1234"`.
# If you store two keys that evaluate as the same string, they WILL override each other.
def [] key
@@ -42,10 +46,11 @@
# Stores a key in the session's data store. If a Redis server is supplied, it will be used to synchronize session data.
#
# Due to scaling considirations, all keys will be converted to strings, so that `"name" == :name` and `1234 == "1234"`.
# If you store two keys that evaluate as the same string, they WILL override each other.
def []= key, value
+ return delete key if value.nil?
key = key.to_s
if (conn=Plezi.redis)
conn.hset @id, key, value
conn.expire @id, SESSION_LIFETIME
return value
@@ -57,9 +62,18 @@
# @return [Hash] returns a shallow copy of the current session data as a Hash.
def to_h
if (conn=Plezi.redis)
conn.expire @id, SESSION_LIFETIME
return conn.hgetall(@id)
+ end
+ failed
+ end
+
+ # @return [String] returns the Session data in YAML format.
+ def to_s
+ if (conn=Plezi.redis)
+ conn.expire @id, SESSION_LIFETIME
+ return conn.hgetall(@id).to_yaml
end
failed
end
# Removes a key from the session's data store.