mongo_session_store 1.0.1 → 1.1.0
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.rdoc → README.md} +26 -14
- data/lib/mongo_session_store.rb +1 -3
- data/lib/mongo_session_store/mongo_mapper.rb +56 -0
- data/lib/mongo_session_store/mongoid.rb +56 -0
- metadata +21 -17
- data/.gitignore +0 -4
- data/Rakefile +0 -19
- data/VERSION +0 -1
- data/lib/mongo_session_store/session_store.rb +0 -54
- data/mongo_session_store.gemspec +0 -54
- data/test/test_helper.rb +0 -10
- data/test/unit/dm_session_store_test.rb +0 -36
data/{README.rdoc → README.md}
RENAMED
@@ -1,28 +1,40 @@
|
|
1
|
-
|
1
|
+
# MongoSessionStore
|
2
2
|
|
3
|
-
|
3
|
+
## Description
|
4
4
|
|
5
|
-
This is a fork of the DataMapper session store, modified to work with
|
6
|
-
and MongoMapper plugin. This plugin is still a work in progress...
|
5
|
+
This is a fork of the DataMapper session store, modified to work with MongoMapper and Mongoid.
|
7
6
|
|
8
|
-
|
7
|
+
## Installation
|
9
8
|
|
10
|
-
|
9
|
+
gem install mongo_session_store
|
11
10
|
|
12
|
-
|
11
|
+
## Usage with MongoMapper
|
13
12
|
|
14
|
-
|
15
|
-
2. In the session_store initializer:
|
13
|
+
In config/environment.rb:
|
16
14
|
|
17
|
-
|
18
|
-
|
15
|
+
config.gem "mongo_mapper"
|
16
|
+
config.gem "mongo_session_store", :lib => "mongo_session_store/mongo_mapper"
|
19
17
|
|
20
|
-
|
18
|
+
In the session_store initializer:
|
21
19
|
|
22
|
-
|
20
|
+
ActionController::Base.session_store = :mongo_mapper_store
|
23
21
|
|
24
|
-
|
22
|
+
## Usage with Mongoid
|
23
|
+
|
24
|
+
In config/environment.rb:
|
25
|
+
|
26
|
+
config.gem "mongoid"
|
27
|
+
config.gem "mongo_session_store"
|
28
|
+
|
29
|
+
In the session_store initializer:
|
25
30
|
|
31
|
+
require "mongo_session_store/mongoid"
|
32
|
+
ActionController::Base.session_store = :mongoid_store
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
Copyright (c) 2010 Nicolas Mérouze
|
37
|
+
Copyright (c) 2009 Chris Brickley
|
26
38
|
Copyright (c) 2009 Tony Pitale
|
27
39
|
|
28
40
|
Permission is hereby granted, free of charge, to any person
|
data/lib/mongo_session_store.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
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
|
+
MongoMapper.ensure_indexes!
|
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
|
@@ -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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_session_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Nicolas M\xC3\xA9rouze"
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2010-
|
14
|
+
date: 2010-02-17 00:00:00 +01:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -26,14 +26,24 @@ dependencies:
|
|
26
26
|
version:
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mongo_mapper
|
29
|
-
type: :
|
29
|
+
type: :development
|
30
30
|
version_requirement:
|
31
31
|
version_requirements: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: 0.6.1
|
36
36
|
version:
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mongoid
|
39
|
+
type: :development
|
40
|
+
version_requirement:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "1.0"
|
46
|
+
version:
|
37
47
|
description:
|
38
48
|
email: nicolas.merouze@gmail.com
|
39
49
|
executables: []
|
@@ -41,17 +51,12 @@ executables: []
|
|
41
51
|
extensions: []
|
42
52
|
|
43
53
|
extra_rdoc_files:
|
44
|
-
- README.
|
54
|
+
- README.md
|
45
55
|
files:
|
46
|
-
- .
|
47
|
-
- README.rdoc
|
48
|
-
- Rakefile
|
49
|
-
- VERSION
|
56
|
+
- README.md
|
50
57
|
- lib/mongo_session_store.rb
|
51
|
-
- lib/mongo_session_store/
|
52
|
-
- mongo_session_store.
|
53
|
-
- test/test_helper.rb
|
54
|
-
- test/unit/dm_session_store_test.rb
|
58
|
+
- lib/mongo_session_store/mongo_mapper.rb
|
59
|
+
- lib/mongo_session_store/mongoid.rb
|
55
60
|
has_rdoc: true
|
56
61
|
homepage: http://github.com/nmerouze/mongo_session_store
|
57
62
|
licenses: []
|
@@ -79,7 +84,6 @@ rubyforge_project:
|
|
79
84
|
rubygems_version: 1.3.5
|
80
85
|
signing_key:
|
81
86
|
specification_version: 3
|
82
|
-
summary: Rails session store class implemented for MongoMapper
|
83
|
-
test_files:
|
84
|
-
|
85
|
-
- test/unit/dm_session_store_test.rb
|
87
|
+
summary: Rails session store class implemented for MongoMapper and Mongoid
|
88
|
+
test_files: []
|
89
|
+
|
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'spec/rake/spectask'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'jeweler'
|
7
|
-
Jeweler::Tasks.new do |gem|
|
8
|
-
gem.name = "mongo_session_store"
|
9
|
-
gem.summary = %Q{Rails session store class implemented for MongoMapper}
|
10
|
-
gem.email = "nicolas.merouze@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/nmerouze/mongo_session_store"
|
12
|
-
gem.authors = ["Nicolas Mérouze", "Tony Pitale", "Chris Brickley"]
|
13
|
-
|
14
|
-
gem.add_dependency('actionpack', '~> 2.3')
|
15
|
-
gem.add_dependency('mongo_mapper', '~> 0.6.1')
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.1
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'mongo_mapper'
|
2
|
-
|
3
|
-
module MongoMapper
|
4
|
-
class SessionStore < ActionController::Session::AbstractStore
|
5
|
-
|
6
|
-
class Session
|
7
|
-
include MongoMapper::Document
|
8
|
-
key :data, String, :default => [Marshal.dump({})].pack("m*")
|
9
|
-
timestamps!
|
10
|
-
|
11
|
-
MongoMapper.ensure_indexes!
|
12
|
-
end
|
13
|
-
|
14
|
-
# The class used for session storage.
|
15
|
-
cattr_accessor :session_class
|
16
|
-
self.session_class = Session
|
17
|
-
|
18
|
-
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
19
|
-
|
20
|
-
private
|
21
|
-
def generate_sid
|
22
|
-
Mongo::ObjectID.new
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_session(env, sid)
|
26
|
-
sid ||= generate_sid
|
27
|
-
session = find_session(sid)
|
28
|
-
env[SESSION_RECORD_KEY] = session
|
29
|
-
[sid, unpack(session.data)]
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_session(env, sid, session_data)
|
33
|
-
record = env[SESSION_RECORD_KEY] ||= find_session(sid)
|
34
|
-
record.data = pack(session_data)
|
35
|
-
#per rack spec: Should return true or false dependant on whether or not the session was saved or not.
|
36
|
-
record.save ? true : false
|
37
|
-
end
|
38
|
-
|
39
|
-
def find_session(id)
|
40
|
-
@@session_class.find(id) ||
|
41
|
-
@@session_class.new(:id=>id)
|
42
|
-
end
|
43
|
-
|
44
|
-
def pack(data)
|
45
|
-
[Marshal.dump(data)].pack("m*")
|
46
|
-
end
|
47
|
-
|
48
|
-
def unpack(packed)
|
49
|
-
return nil unless packed
|
50
|
-
Marshal.load(packed.unpack("m*").first)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
data/mongo_session_store.gemspec
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{mongo_session_store}
|
8
|
-
s.version = "1.0.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Nicolas M\303\251rouze", "Tony Pitale", "Chris Brickley"]
|
12
|
-
s.date = %q{2010-01-22}
|
13
|
-
s.email = %q{nicolas.merouze@gmail.com}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"README.rdoc"
|
16
|
-
]
|
17
|
-
s.files = [
|
18
|
-
".gitignore",
|
19
|
-
"README.rdoc",
|
20
|
-
"Rakefile",
|
21
|
-
"VERSION",
|
22
|
-
"lib/mongo_session_store.rb",
|
23
|
-
"lib/mongo_session_store/session_store.rb",
|
24
|
-
"mongo_session_store.gemspec",
|
25
|
-
"test/test_helper.rb",
|
26
|
-
"test/unit/dm_session_store_test.rb"
|
27
|
-
]
|
28
|
-
s.homepage = %q{http://github.com/nmerouze/mongo_session_store}
|
29
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
-
s.require_paths = ["lib"]
|
31
|
-
s.rubygems_version = %q{1.3.5}
|
32
|
-
s.summary = %q{Rails session store class implemented for MongoMapper}
|
33
|
-
s.test_files = [
|
34
|
-
"test/test_helper.rb",
|
35
|
-
"test/unit/dm_session_store_test.rb"
|
36
|
-
]
|
37
|
-
|
38
|
-
if s.respond_to? :specification_version then
|
39
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
-
s.specification_version = 3
|
41
|
-
|
42
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
-
s.add_runtime_dependency(%q<actionpack>, ["~> 2.3"])
|
44
|
-
s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
45
|
-
else
|
46
|
-
s.add_dependency(%q<actionpack>, ["~> 2.3"])
|
47
|
-
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
48
|
-
end
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<actionpack>, ["~> 2.3"])
|
51
|
-
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
data/test/test_helper.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# http://sneaq.net/textmate-wtf
|
2
|
-
$:.reject! { |e| e.include? 'TextMate' }
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'test/unit'
|
6
|
-
require 'shoulda'
|
7
|
-
require 'mocha'
|
8
|
-
require 'action_controller' # version >= 2.3.0
|
9
|
-
|
10
|
-
require File.dirname(__FILE__) + '/../lib/dm_session_store'
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
-
|
3
|
-
module DataMapper
|
4
|
-
class SessionStoreTest < Test::Unit::TestCase
|
5
|
-
context "An instance of the SessionStore class" do
|
6
|
-
setup do
|
7
|
-
@session_klass = SessionStore::Session
|
8
|
-
@session_store = SessionStore.new('app')
|
9
|
-
end
|
10
|
-
|
11
|
-
should "get a session" do
|
12
|
-
env = {}
|
13
|
-
session = stub(:data => 'data')
|
14
|
-
@session_store.expects(:find_session).with(1).returns(session)
|
15
|
-
assert_equal([1, 'data'], @session_store.send(:get_session, env, 1))
|
16
|
-
assert_equal({'rack.session.record' => session}, env)
|
17
|
-
end
|
18
|
-
|
19
|
-
should "set a session" do
|
20
|
-
env = {}
|
21
|
-
session = stub
|
22
|
-
session.expects(:data=).with({:color => 'yellow'})
|
23
|
-
session.stubs(:save).returns(true)
|
24
|
-
@session_store.expects(:find_session).with(1).returns(session)
|
25
|
-
assert @session_store.send(:set_session, env, 1, {:color => 'yellow'})
|
26
|
-
assert_equal({'rack.session.record' => session}, env)
|
27
|
-
end
|
28
|
-
|
29
|
-
should "find a session" do
|
30
|
-
@session_klass.expects(:first).with(:session_id => 1).returns(nil)
|
31
|
-
@session_klass.expects(:new).with(:session_id => 1, :data => {}).returns('session')
|
32
|
-
assert_equal 'session', @session_store.send(:find_session, 1)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|