class RodaSessionMiddleware::SessionHash
string.
for other reasons, manually create a session id using a randomly generated
that are loaded out of a database. If you need to have a session id
one is not needed for cookie-based sessions, only for sessions
is that SessionHash does not attempt to setup a session id, since
One difference between SessionHash and Rack::Session::Abstract::SessionHash
keys to strings.
session from the cookie if it hasn’t been loaded yet, and convert
Undocumented methods operate the same as hash methods, but load the
of Rack::Session::Abstract::SessionHash, but is simpler and faster.
Class to hold session data. This is designed to mimic the API
def [](key)
def [](key) load! @data[key.to_s] end
def []=(key, value)
def []=(key, value) load! @data[key.to_s] = value end
def clear
keys from the environment so that the related cookie will
Clear the session, also removing a couple of roda session
def clear load! env = @req.env env.delete('roda.session.created_at') env.delete('roda.session.updated_at') @data.clear end
def delete(key)
def delete(key) load! @data.delete(key.to_s) end
def each(&block)
def each(&block) load! @data.each(&block) end
def empty?
def empty? load! @data.empty? end
def exists?
Return whether the session cookie already exists.
def exists? load! req.env.has_key?('roda.session.serialized') end
def fetch(key, default = (no_default = true), &block)
def fetch(key, default = (no_default = true), &block) load! if no_default @data.fetch(key.to_s, &block) else @data.fetch(key.to_s, default, &block) end end
def has_key?(key)
def has_key?(key) load! @data.has_key?(key.to_s) end
def initialize(req)
def initialize(req) @req = req end
def inspect
def inspect if loaded? @data.inspect else "#<#{self.class}:0x#{self.object_id.to_s(16)} not yet loaded>" end end
def keys
def keys load! @data.keys end
def load!
def load! @data ||= @req.send(:_load_session) end
def loaded?
def loaded? !!defined?(@data) end
def options
The Roda sessions plugin options used by the middleware for this
def options @req.roda_class.opts[:sessions] end
def replace(hash)
def replace(hash) load! @data.clear update(hash) end
def to_hash
def to_hash load! @data.dup end
def update(hash)
def update(hash) load! hash.each do |key, value| @data[key.to_s] = value end @data end
def values
def values load! @data.values end