Class: Rack::Session::Abstract::ID

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rack-0.4.0/lib/rack/session/abstract/id.rb

Overview

ID sets up a basic framework for implementing an id based sessioning service. Cookies sent to the client for maintaining sessions will only contain an id reference. Only #get_session and #set_session should need to be overwritten.

All parameters are optional.

  • :key determines the name of the cookie, by default it is ‘rack.session’

  • :domain and :path set the related cookie values, by default domain is nil, and the path is ‘/’.

  • :expire_after is the number of seconds in which the session cookie will expire. By default it is set not to provide any expiry time.

Direct Known Subclasses

Memcache, Pool

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :key =>           'rack.session',
  :path =>          '/',
  :domain =>        nil,
  :expire_after =>  nil
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ ID

Returns a new instance of ID.



32
33
34
35
36
# File 'lib/gems/rack-0.4.0/lib/rack/session/abstract/id.rb', line 32

def initialize(app, options={})
  @default_options = self.class::DEFAULT_OPTIONS.merge(options)
  @key = @default_options[:key]
  @default_context = context app
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



24
25
26
# File 'lib/gems/rack-0.4.0/lib/rack/session/abstract/id.rb', line 24

def key
  @key
end

Instance Method Details

#call(env) ⇒ Object



38
39
40
# File 'lib/gems/rack-0.4.0/lib/rack/session/abstract/id.rb', line 38

def call(env)
  @default_context.call(env)
end

#context(app) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/gems/rack-0.4.0/lib/rack/session/abstract/id.rb', line 42

def context(app)
  Rack::Utils::Context.new self, app do |env|
    load_session env
    response = app.call(env)
    commit_session env, response
    response
  end
end