forked from mongoid/mongo_session_store
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
133 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.1 | ||
1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
$:.unshift File.dirname(__FILE__) | ||
|
||
require 'mongo_session_store/session_store' | ||
$:.unshift File.dirname(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'mongo_mapper' | ||
|
||
module ActionController | ||
module Session | ||
class MongoMapperStore < AbstractStore | ||
|
||
class Session | ||
include MongoMapper::Document | ||
key :data, String, :default => [Marshal.dump({})].pack("m*") | ||
timestamps! | ||
|
||
MongoMapper.ensure_indexes! | ||
end | ||
|
||
# The class used for session storage. | ||
cattr_accessor :session_class | ||
self.session_class = Session | ||
|
||
SESSION_RECORD_KEY = 'rack.session.record'.freeze | ||
|
||
private | ||
def generate_sid | ||
Mongo::ObjectID.new | ||
end | ||
|
||
def get_session(env, sid) | ||
sid ||= generate_sid | ||
session = find_session(sid) | ||
env[SESSION_RECORD_KEY] = session | ||
[sid, unpack(session.data)] | ||
end | ||
|
||
def set_session(env, sid, session_data) | ||
record = env[SESSION_RECORD_KEY] ||= find_session(sid) | ||
record.data = pack(session_data) | ||
#per rack spec: Should return true or false dependant on whether or not the session was saved or not. | ||
record.save ? true : false | ||
end | ||
|
||
def find_session(id) | ||
@@session_class.find(id) || | ||
@@session_class.new(:id=>id) | ||
end | ||
|
||
def pack(data) | ||
[Marshal.dump(data)].pack("m*") | ||
end | ||
|
||
def unpack(packed) | ||
return nil unless packed | ||
Marshal.load(packed.unpack("m*").first) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'mongoid' | ||
|
||
module ActionController | ||
module Session | ||
class MongoidStore < AbstractStore | ||
|
||
class Session | ||
include Mongoid::Document | ||
include Mongoid::Timestamps | ||
|
||
field :data, :type => String, :default => [Marshal.dump({})].pack("m*") | ||
index :updated_at | ||
end | ||
|
||
# The class used for session storage. | ||
cattr_accessor :session_class | ||
self.session_class = Session | ||
|
||
SESSION_RECORD_KEY = 'rack.session.record'.freeze | ||
|
||
private | ||
def generate_sid | ||
Mongo::ObjectID.new | ||
end | ||
|
||
def get_session(env, sid) | ||
sid ||= generate_sid | ||
session = find_session(sid) | ||
env[SESSION_RECORD_KEY] = session | ||
[sid, unpack(session.data)] | ||
end | ||
|
||
def set_session(env, sid, session_data) | ||
record = env[SESSION_RECORD_KEY] ||= find_session(sid) | ||
record.data = pack(session_data) | ||
#per rack spec: Should return true or false dependant on whether or not the session was saved or not. | ||
record.save ? true : false | ||
end | ||
|
||
def find_session(id) | ||
@@session_class.find(id) || | ||
@@session_class.new(:id=>id) | ||
end | ||
|
||
def pack(data) | ||
[Marshal.dump(data)].pack("m*") | ||
end | ||
|
||
def unpack(packed) | ||
return nil unless packed | ||
Marshal.load(packed.unpack("m*").first) | ||
end | ||
|
||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.