Class: N::Session

Inherits:
Hash show all
Defined in:
lib/nitro/session.rb

Overview

A web application session.

State is a neccessary evil but session variables should be avoided as much as possible. Session state is typically distributed to many servers so avoid storing complete objects in session variables, only store oids and small integer/strings.

The session should be persistable to survive server shutdowns.

Constant Summary collapse

@@manager =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = nil) ⇒ Session

Create the session for the given context.



59
60
61
# File 'lib/nitro/session.rb', line 59

def initialize(context = nil)
	@session_id = create_id
end

Instance Attribute Details

#session_idObject (readonly)

The unique id of this session.



41
42
43
# File 'lib/nitro/session.rb', line 41

def session_id
  @session_id
end

Class Method Details

.lookup(context) ⇒ Object



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

def self.lookup(context)
	if cookie = context.cookies[Session.cookie_name]
		session = context.sessions[cookie]
	end

	unless session
		session = Session.new(context)
		context.add_cookie(Cookie.new(Session.cookie_name, session.session_id))
		context.sessions[session.session_id] = session
	end
	
	return session
end