gscalzo-mongo_session_store 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +60 -0
- data/lib/mongo_session_store.rb +1 -0
- data/lib/mongo_session_store/mongo_mapper.rb +58 -0
- data/lib/mongo_session_store/mongoid.rb +56 -0
- metadata +117 -0
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# MongoSessionStore
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
This is a fork of the DataMapper session store, modified to work with MongoMapper and Mongoid.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install mongo_session_store
|
10
|
+
|
11
|
+
## Usage with MongoMapper
|
12
|
+
|
13
|
+
In config/environment.rb:
|
14
|
+
|
15
|
+
config.gem "mongo_mapper"
|
16
|
+
config.gem "mongo_session_store"
|
17
|
+
|
18
|
+
In the session_store initializer:
|
19
|
+
|
20
|
+
require "mongo_session_store/mongo_mapper"
|
21
|
+
ActionController::Base.session_store = :mongo_mapper_store
|
22
|
+
|
23
|
+
## Usage with Mongoid
|
24
|
+
|
25
|
+
In config/environment.rb:
|
26
|
+
|
27
|
+
config.gem "mongoid"
|
28
|
+
config.gem "mongo_session_store"
|
29
|
+
|
30
|
+
In the session_store initializer:
|
31
|
+
|
32
|
+
require "mongo_session_store/mongoid"
|
33
|
+
ActionController::Base.session_store = :mongoid_store
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
Copyright (c) 2010 Nicolas Mérouze
|
38
|
+
Copyright (c) 2009 Chris Brickley
|
39
|
+
Copyright (c) 2009 Tony Pitale
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person
|
42
|
+
obtaining a copy of this software and associated documentation
|
43
|
+
files (the "Software"), to deal in the Software without
|
44
|
+
restriction, including without limitation the rights to use,
|
45
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
46
|
+
copies of the Software, and to permit persons to whom the
|
47
|
+
Software is furnished to do so, subject to the following
|
48
|
+
conditions:
|
49
|
+
|
50
|
+
The above copyright notice and this permission notice shall be
|
51
|
+
included in all copies or substantial portions of the Software.
|
52
|
+
|
53
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
54
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
55
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
56
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
57
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
58
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
59
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
60
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
|
3
|
+
module ActionController
|
4
|
+
module Session
|
5
|
+
class MongoMapperStore < AbstractStore
|
6
|
+
|
7
|
+
class Session
|
8
|
+
include MongoMapper::Document
|
9
|
+
key :data, String, :default => [Marshal.dump({})].pack("m*")
|
10
|
+
timestamps!
|
11
|
+
|
12
|
+
ensure_index :updated_at
|
13
|
+
end
|
14
|
+
|
15
|
+
# The class used for session storage.
|
16
|
+
cattr_accessor :session_class
|
17
|
+
self.session_class = Session
|
18
|
+
|
19
|
+
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
20
|
+
|
21
|
+
private
|
22
|
+
def generate_sid
|
23
|
+
BSON::ObjectId.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_session(env, sid)
|
27
|
+
sid ||= generate_sid
|
28
|
+
session = find_session(sid)
|
29
|
+
env[SESSION_RECORD_KEY] = session
|
30
|
+
[sid, unpack(session.data)]
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_session(env, sid, session_data)
|
34
|
+
record = env[SESSION_RECORD_KEY] ||= find_session(sid)
|
35
|
+
record.data = pack(session_data)
|
36
|
+
#per rack spec: Should return true or false dependant on whether or not the session was saved or not.
|
37
|
+
record.save ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_session(id)
|
41
|
+
@@session_class.find(id) ||
|
42
|
+
@@session_class.new(:id=>id)
|
43
|
+
rescue BSON::InvalidObjectId
|
44
|
+
@@session_class.new(:id => generate_sid)
|
45
|
+
end
|
46
|
+
|
47
|
+
def pack(data)
|
48
|
+
[Marshal.dump(data)].pack("m*")
|
49
|
+
end
|
50
|
+
|
51
|
+
def unpack(packed)
|
52
|
+
return nil unless packed
|
53
|
+
Marshal.load(packed.unpack("m*").first)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
|
3
|
+
module ActionController
|
4
|
+
module Session
|
5
|
+
class MongoidStore < AbstractStore
|
6
|
+
|
7
|
+
class Session
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Timestamps
|
10
|
+
|
11
|
+
field :data, :type => String, :default => [Marshal.dump({})].pack("m*")
|
12
|
+
index :updated_at
|
13
|
+
end
|
14
|
+
|
15
|
+
# The class used for session storage.
|
16
|
+
cattr_accessor :session_class
|
17
|
+
self.session_class = Session
|
18
|
+
|
19
|
+
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
20
|
+
|
21
|
+
private
|
22
|
+
def generate_sid
|
23
|
+
Mongo::ObjectId.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_session(env, sid)
|
27
|
+
sid ||= generate_sid
|
28
|
+
session = find_session(sid)
|
29
|
+
env[SESSION_RECORD_KEY] = session
|
30
|
+
[sid, unpack(session.data)]
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_session(env, sid, session_data)
|
34
|
+
record = env[SESSION_RECORD_KEY] ||= find_session(sid)
|
35
|
+
record.data = pack(session_data)
|
36
|
+
#per rack spec: Should return true or false dependant on whether or not the session was saved or not.
|
37
|
+
record.save ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
def find_session(id)
|
41
|
+
@@session_class.find(id) ||
|
42
|
+
@@session_class.new(:id=>id)
|
43
|
+
end
|
44
|
+
|
45
|
+
def pack(data)
|
46
|
+
[Marshal.dump(data)].pack("m*")
|
47
|
+
end
|
48
|
+
|
49
|
+
def unpack(packed)
|
50
|
+
return nil unless packed
|
51
|
+
Marshal.load(packed.unpack("m*").first)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gscalzo-mongo_session_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 3
|
10
|
+
version: 1.1.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Nicolas M\xC3\xA9rouze"
|
14
|
+
- Tony Pitale
|
15
|
+
- Chris Brickley
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2010-09-17 00:00:00 +02:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: actionpack
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 5
|
32
|
+
segments:
|
33
|
+
- 2
|
34
|
+
- 3
|
35
|
+
version: "2.3"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: mongo_mapper
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 5
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 6
|
50
|
+
- 1
|
51
|
+
version: 0.6.1
|
52
|
+
type: :development
|
53
|
+
version_requirements: *id002
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: mongoid
|
56
|
+
prerelease: false
|
57
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 15
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 0
|
66
|
+
version: "1.0"
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
description:
|
70
|
+
email: nicolas.merouze@gmail.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files:
|
76
|
+
- README.md
|
77
|
+
files:
|
78
|
+
- README.md
|
79
|
+
- lib/mongo_session_store.rb
|
80
|
+
- lib/mongo_session_store/mongo_mapper.rb
|
81
|
+
- lib/mongo_session_store/mongoid.rb
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://github.com/nmerouze/mongo_session_store
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options:
|
88
|
+
- --charset=UTF-8
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Rails session store class implemented for MongoMapper and Mongoid
|
116
|
+
test_files: []
|
117
|
+
|