lib/global_session/session.rb in global_session-1.0.13 vs lib/global_session/session.rb in global_session-1.0.14
- old
+ new
@@ -78,9 +78,34 @@
else
create_invalid
end
end
+ # @return a Hash representation of the session with three subkeys: :metadata, :signed and :insecure
+ # @raise nothing -- does not raise; returns empty hash if there is a failure
+ def to_hash
+ hash = {}
+
+ md = {}
+ signed = {}
+ insecure = {}
+
+ hash[:metadata] = md
+ hash[:signed] = signed
+ hash[:insecure] = insecure
+
+ md[:id] = @id
+ md[:authority] = @authority
+ md[:created_at] = @created_at
+ md[:expired_at] = @expired_at
+ @signed.each_pair { |k, v| signed[k] = v }
+ @insecure.each_pair { |k, v| insecure[k] = v }
+
+ hash
+ rescue Exception => e
+ {}
+ end
+
# Determine whether the session is valid. This method simply delegates to the
# directory associated with this session.
#
# === Return
# valid(true|false):: True if the session is valid, false otherwise