Module: Camping::Session
- Defined in:
- lib/camping/session.rb
Overview
Getting Started
To get sessions working for your application:
-
require 'camping/session'
-
Define a secret (and keep it secret):
set :secret, "SECRET!"
-
Mixin the module:
include Camping::Session
-
Throughout your application, use the
@state
var like a hash to store your application’s data.
require 'camping/session' # 1
module Nuts
set :secret, "Oh yeah!" # 2
include Camping::Session # 3
end
Other backends
Camping only ships with session-cookies. However, the @state
variable is simply a shortcut for @env['rack.session']
. Therefore you can also use any middleware which sets this variable:
module Nuts
use Rack::Session::Memcache
end
Class Method Summary collapse
Class Method Details
.included(app) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/camping/session.rb', line 28 def self.included(app) key = "#{app}.state".downcase secret = app.[:secret] || [__FILE__, File.mtime(__FILE__)].join(":") app.use Rack::Session::Cookie, :key => key, :secret => secret end |