mongo_session_store 1.0.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/.gitignore +4 -0
- data/README.rdoc +47 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/mongo_session_store.rb +3 -0
- data/lib/mongo_session_store/session_store.rb +54 -0
- data/mongo_session_store.gemspec +54 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/dm_session_store_test.rb +36 -0
- metadata +85 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= MongoSessionStore
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
This is a fork of the DataMapper session store, modified to work with MongoDB
|
6
|
+
and MongoMapper plugin. This plugin is still a work in progress...
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
TBD
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
1. Clone/submodule to vendor/plugins/mongo_session_store
|
15
|
+
2. In the session_store initializer:
|
16
|
+
|
17
|
+
require 'mongo_session_store'
|
18
|
+
ActionController::Base.session_store = MongoMapper::SessionStore
|
19
|
+
|
20
|
+
Obviously, for this to work, you must already have MongoMapper installed.
|
21
|
+
|
22
|
+
== License
|
23
|
+
|
24
|
+
Copyright (c) 2009 Chris Brickley
|
25
|
+
|
26
|
+
Copyright (c) 2009 Tony Pitale
|
27
|
+
|
28
|
+
Permission is hereby granted, free of charge, to any person
|
29
|
+
obtaining a copy of this software and associated documentation
|
30
|
+
files (the "Software"), to deal in the Software without
|
31
|
+
restriction, including without limitation the rights to use,
|
32
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
33
|
+
copies of the Software, and to permit persons to whom the
|
34
|
+
Software is furnished to do so, subject to the following
|
35
|
+
conditions:
|
36
|
+
|
37
|
+
The above copyright notice and this permission notice shall be
|
38
|
+
included in all copies or substantial portions of the Software.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
42
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
43
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
44
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
45
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
46
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
47
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
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('actioncontroller', '~> 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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,54 @@
|
|
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
|
@@ -0,0 +1,54 @@
|
|
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.0"
|
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<actioncontroller>, ["~> 2.3"])
|
44
|
+
s.add_runtime_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<actioncontroller>, ["~> 2.3"])
|
47
|
+
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
48
|
+
end
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<actioncontroller>, ["~> 2.3"])
|
51
|
+
s.add_dependency(%q<mongo_mapper>, ["~> 0.6.1"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
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'
|
@@ -0,0 +1,36 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongo_session_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Nicolas M\xC3\xA9rouze"
|
8
|
+
- Tony Pitale
|
9
|
+
- Chris Brickley
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2010-01-22 00:00:00 +01:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: actioncontroller
|
19
|
+
type: :runtime
|
20
|
+
version_requirement:
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: "2.3"
|
26
|
+
version:
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mongo_mapper
|
29
|
+
type: :runtime
|
30
|
+
version_requirement:
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.6.1
|
36
|
+
version:
|
37
|
+
description:
|
38
|
+
email: nicolas.merouze@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- README.rdoc
|
48
|
+
- Rakefile
|
49
|
+
- VERSION
|
50
|
+
- lib/mongo_session_store.rb
|
51
|
+
- lib/mongo_session_store/session_store.rb
|
52
|
+
- mongo_session_store.gemspec
|
53
|
+
- test/test_helper.rb
|
54
|
+
- test/unit/dm_session_store_test.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/nmerouze/mongo_session_store
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --charset=UTF-8
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: Rails session store class implemented for MongoMapper
|
83
|
+
test_files:
|
84
|
+
- test/test_helper.rb
|
85
|
+
- test/unit/dm_session_store_test.rb
|