lib/global_session/session/abstract.rb in global_session-3.2.0 vs lib/global_session/session/abstract.rb in global_session-3.2.1

- old
+ new

@@ -42,11 +42,11 @@ "<#{self.class.name}(#{self.id})>" 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 + def to_h hash = {} md = {} signed = {} insecure = {} @@ -65,10 +65,13 @@ hash rescue Exception => e {} end + # @deprecated will be removed in GlobalSession v4; please use to_h instead + alias to_hash to_h + # @return [true,false] true if this session was created in-process, false if it was initialized from a cookie def new_record? @cookie.nil? end @@ -79,10 +82,17 @@ # valid(true|false):: True if the session is valid, false otherwise def valid? @directory.valid_session?(@id, @expired_at) end + # Determine whether any state has changed since the session was loaded. + # + # @return [Boolean] true if something has changed + def dirty? + !!(new_record? || @dirty_timestamps) + end + # Determine whether the global session schema allows a given key to be placed # in the global session. # # === Parameters # key(String):: The name of the key @@ -102,11 +112,11 @@ # contained(true|false):: Whether the session currently has a value for the specified key. def has_key?(key) @signed.has_key?(key) || @insecure.has_key?(key) end - alias :key? :has_key? + alias key? has_key? # Invalidate this session by reporting its UUID to the Directory. # # === Return # unknown(Object):: Returns whatever the Directory returns @@ -123,9 +133,10 @@ authority_check minutes = Integer(@configuration['timeout']) expired_at ||= Time.at(Time.now.utc + 60 * minutes) @expired_at = expired_at @created_at = Time.now.utc + @dirty_timestamps = true end private def authority_check # :nodoc: \ No newline at end of file