class ActionDispatch::Session::MongoidStore
Constants
- ENV_SESSION_OPTIONS_KEY
- SESSION_RECORD_KEY
Private Instance Methods
destroy(env)
click to toggle source
def destroy(env)
if sid = current_session_id(env) find_session(sid).destroy end
end
# File lib/mongoid3_session_store/mongoid_store.rb, line 50 def destroy(env) destroy_session(env, current_session_id(env), {}) end
destroy_session(env, session_id, options)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 54 def destroy_session(env, session_id, options) if sid = current_session_id(env) get_session_model(env, sid).destroy env[SESSION_RECORD_KEY] = nil end generate_sid unless options[:drop] end
find_session(id)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 40 def find_session(id) @@session_class.find_or_create_by(:sid => id) end
get_session(env, sid)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 23 def get_session(env, sid) sid ||= generate_sid session = find_session(sid) env[SESSION_RECORD_KEY] = session [sid, unpack(session.data)] end
get_session_model(env, sid)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 63 def get_session_model(env, sid) if env[ENV_SESSION_OPTIONS_KEY][:id].nil? env[SESSION_RECORD_KEY] = find_session(sid) else env[SESSION_RECORD_KEY] ||= find_session(sid) end end
pack(data)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 71 def pack(data) [Marshal.dump(data)].pack("m*") end
set_session(env, sid, session_data, options = nil)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 30 def set_session(env, sid, session_data, options = nil) record = get_session_model(env, sid) record.data = pack(session_data) # Rack spec dictates that set_session should return true or false # depending on whether or not the session was saved or not. # However, ActionPack seems to want a session id instead. record.save ? sid : false end
unpack(packed)
click to toggle source
# File lib/mongoid3_session_store/mongoid_store.rb, line 75 def unpack(packed) return nil unless packed Marshal.load(packed.unpack("m*").first) end