class Rack::Session::Mongo
Constants
- DEFAULT_OPTIONS
- VERSION
Public Class Methods
new(app, options={})
click to toggle source
Calls superclass method
# File lib/mongo-rack-session.rb, line 34 def initialize(app, options={}) super @key = options[:key] || @default_options[:default_key] # set up the Session Class either defined by the User or using the one defined above @@session_class = options[:session_class] || Session @@session_class.set_database_name(options[:mongo_db_name] || @default_options[:mongo_db_name]) @@session_class.set_collection_name(options[:mongo_collection_name] || @default_options[:mongo_collection_name]) @@session_class.connection(::Mongo::Connection.new(options[:mongo_server] || @default_options[:mongo_server])) @@session_class_key = options[:session_class_key] || @default_options[:session_class_key] end
Public Instance Methods
find_session(sid)
click to toggle source
# File lib/mongo-rack-session.rb, line 56 def find_session(sid) mongo_session = @@session_class.first(:conditions => {@@session_class_key => sid}) (mongo_session && mongo_session.is_valid?) || @@session_class.create(@@session_class_key => sid) end
generate_sid()
click to toggle source
# File lib/mongo-rack-session.rb, line 61 def generate_sid UUID.generate end
get_session(env, sid)
click to toggle source
# File lib/mongo-rack-session.rb, line 46 def get_session(env, sid) sid ||= generate_sid session = find_session(sid) [sid, session] end
set_session(env, session_id, new_session, options)
click to toggle source
# File lib/mongo-rack-session.rb, line 52 def set_session(env, session_id, new_session, options) #new_session.save ? new_session.Id : nil end