Class: Rack::Session::Cookie

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rack-0.9.1/lib/rack/session/cookie.rb

Overview

Rack::Session::Cookie provides simple cookie based session management. The session is a Ruby Hash stored as base64 encoded marshalled data set to :key (default: rack.session). When the secret key is set, cookie data is checked for data integrity.

Example:

use Rack::Session::Cookie, :key => 'rack.session',
                           :domain => 'foo.com',
                           :path => '/',
                           :expire_after => 2592000,
                           :secret => 'change_me'

All parameters are optional.

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Cookie.



24
25
26
27
28
29
30
31
# File 'lib/gems/rack-0.9.1/lib/rack/session/cookie.rb', line 24

def initialize(app, options={})
  @app = app
  @key = options[:key] || "rack.session"
  @secret = options[:secret]
  @default_options = {:domain => nil,
    :path => "/",
    :expire_after => nil}.merge(options)
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
# File 'lib/gems/rack-0.9.1/lib/rack/session/cookie.rb', line 33

def call(env)
  load_session(env)
  status, headers, body = @app.call(env)
  commit_session(env, status, headers, body)
end