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

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rack-0.9.1/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,
  :secure =>        false,
  :httponly =>      true,
  :sidbits =>       128
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ID.



35
36
37
38
39
# File 'lib/gems/rack-0.9.1/lib/rack/session/abstract/id.rb', line 35

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.9.1/lib/rack/session/abstract/id.rb', line 24

def key
  @key
end

Instance Method Details

#call(env) ⇒ Object



41
42
43
# File 'lib/gems/rack-0.9.1/lib/rack/session/abstract/id.rb', line 41

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

#context(app) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/gems/rack-0.9.1/lib/rack/session/abstract/id.rb', line 45

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