Module: GlobalSession::Session

Defined in:
lib/global_session/session.rb,
lib/global_session/session.rb,
lib/global_session/session/v1.rb,
lib/global_session/session/v2.rb,
lib/global_session/session/v3.rb,
lib/global_session/session/v4.rb,
lib/global_session/session/abstract.rb

Overview

Ladies and gentlemen: the one and only, star of the show, GLOBAL SESSION!

Session is designed to act as much like a Hash as possible. You can use most of the methods you would use with Hash: [], has_key?, each, etc. It has a few additional methods that are specific to itself, mostly involving whether it’s expired, valid, supports a certain key, etc.

Global sessions are versioned, and each version may have its own encoding strategy. This module acts as a namespace for the different versions, each of which is represented by a class in the module. They all inherit from the abstract base class in order to ensure that they are internally compatible with other components of this gem.

This module also acts as a façade for reading global session cookies generated by the different versions; it is responsible for detecting the version of a given cookie, then instantiating a suitable session object.

Defined Under Namespace

Classes: Abstract, V1, V2, V3, V4

Class Method Summary collapse

Class Method Details

Decode a global session cookie without checking signature or expiration. Good for debugging.



30
31
32
# File 'lib/global_session/session.rb', line 30

def self.decode_cookie(cookie)
  guess_version(cookie).decode_cookie(cookie)
end

.guess_version(cookie) ⇒ Class

Figure out the protocol version of a serialized session cookie.

Parameters:

  • cookie (String)

Returns:

  • (Class)

    implementation class that can probably deserialize cookie



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/global_session/session.rb', line 44

def self.guess_version(cookie)
  case cookie
  when V4::HEADER
    V4
  when nil, V3::HEADER
    V3
  when V2::HEADER
    V2
  else
    V1 # due to zlib compression, no foolproof way to spot V1 sessoins
  end
end

.new(directory, cookie = nil) ⇒ Object

Decode a global session cookie. Use a heuristic to determine the version.

Raises:



36
37
38
# File 'lib/global_session/session.rb', line 36

def self.new(directory, cookie=nil)
  guess_version(cookie).new(directory, cookie)
end