mongo_session_store-rails3 4.1.1 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/install.log +768 -0
- data/.travis.yml +2 -3
- data/Gemfile +21 -18
- data/README.md +23 -41
- data/Rakefile +32 -21
- data/lib/mongo_session_store-rails3.rb +1 -50
- data/lib/mongo_session_store-rails4.rb +1 -0
- data/lib/mongo_session_store.rb +49 -0
- data/lib/mongo_session_store/mongo_store.rb +0 -4
- data/lib/mongo_session_store/mongoid_store.rb +29 -5
- data/lib/mongo_session_store/version.rb +1 -1
- data/mongo_session_store-rails3.gemspec +2 -2
- data/mongo_session_store-rails4.gemspec +17 -0
- data/spec/rails_3.1_app/config/initializers/devise.rb +1 -1
- data/spec/rails_3.2_app/config/initializers/devise.rb +3 -1
- data/spec/rails_4.0_app/.gitignore +16 -0
- data/spec/rails_4.0_app/Rakefile +6 -0
- data/spec/rails_4.0_app/app/assets/images/.keep +0 -0
- data/spec/rails_4.0_app/app/assets/javascripts/application.js +13 -0
- data/spec/rails_4.0_app/app/assets/stylesheets/application.css +13 -0
- data/spec/rails_4.0_app/app/controllers/application_controller.rb +5 -0
- data/spec/rails_4.0_app/app/controllers/concerns/.keep +0 -0
- data/spec/rails_4.0_app/app/controllers/home_controller.rb +4 -0
- data/spec/rails_4.0_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_4.0_app/app/mailers/.keep +0 -0
- data/spec/rails_4.0_app/app/models/.keep +0 -0
- data/spec/rails_4.0_app/app/models/concerns/.keep +0 -0
- data/spec/rails_4.0_app/app/models/user.rb +5 -0
- data/spec/rails_4.0_app/app/views/devise/confirmations/new.html.erb +12 -0
- data/spec/rails_4.0_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/spec/rails_4.0_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/spec/rails_4.0_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/spec/rails_4.0_app/app/views/devise/passwords/edit.html.erb +16 -0
- data/spec/rails_4.0_app/app/views/devise/passwords/new.html.erb +12 -0
- data/spec/rails_4.0_app/app/views/devise/registrations/edit.html.erb +29 -0
- data/spec/rails_4.0_app/app/views/devise/registrations/new.html.erb +18 -0
- data/spec/rails_4.0_app/app/views/devise/sessions/new.html.erb +17 -0
- data/spec/rails_4.0_app/app/views/devise/shared/_links.erb +25 -0
- data/spec/rails_4.0_app/app/views/devise/unlocks/new.html.erb +12 -0
- data/spec/rails_4.0_app/app/views/home/index.html.erb +10 -0
- data/spec/rails_4.0_app/app/views/layouts/application.html.erb +17 -0
- data/spec/rails_4.0_app/bin/bundle +3 -0
- data/spec/rails_4.0_app/bin/rails +4 -0
- data/spec/rails_4.0_app/bin/rake +4 -0
- data/spec/rails_4.0_app/config.ru +4 -0
- data/spec/rails_4.0_app/config/application.rb +26 -0
- data/spec/rails_4.0_app/config/boot.rb +4 -0
- data/spec/rails_4.0_app/config/database.yml +11 -0
- data/spec/rails_4.0_app/config/environment.rb +5 -0
- data/spec/rails_4.0_app/config/environments/development.rb +29 -0
- data/spec/rails_4.0_app/config/environments/production.rb +80 -0
- data/spec/rails_4.0_app/config/environments/test.rb +36 -0
- data/spec/rails_4.0_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_4.0_app/config/initializers/devise.rb +254 -0
- data/spec/rails_4.0_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails_4.0_app/config/initializers/inflections.rb +16 -0
- data/spec/rails_4.0_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_4.0_app/config/initializers/secret_token.rb +12 -0
- data/spec/rails_4.0_app/config/initializers/session_store.rb +5 -0
- data/spec/rails_4.0_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_4.0_app/config/locales/devise.en.yml +59 -0
- data/spec/rails_4.0_app/config/locales/en.yml +23 -0
- data/spec/rails_4.0_app/config/mongo.yml +11 -0
- data/spec/rails_4.0_app/config/mongoid.yml +13 -0
- data/spec/rails_4.0_app/config/routes.rb +4 -0
- data/spec/rails_4.0_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
- data/spec/rails_4.0_app/db/schema.rb +25 -0
- data/spec/rails_4.0_app/db/seeds.rb +7 -0
- data/spec/rails_4.0_app/lib/assets/.keep +0 -0
- data/spec/rails_4.0_app/lib/tasks/.keep +0 -0
- data/spec/rails_4.0_app/log/.keep +0 -0
- data/spec/rails_4.0_app/public/404.html +58 -0
- data/spec/rails_4.0_app/public/422.html +58 -0
- data/spec/rails_4.0_app/public/500.html +57 -0
- data/spec/rails_4.0_app/public/favicon.ico +0 -0
- data/spec/rails_4.0_app/public/robots.txt +5 -0
- data/spec/rails_4.1_app/.gitignore +16 -0
- data/spec/rails_4.1_app/Rakefile +6 -0
- data/spec/rails_4.1_app/app/assets/images/.keep +0 -0
- data/spec/rails_4.1_app/app/assets/javascripts/application.js +13 -0
- data/spec/rails_4.1_app/app/assets/stylesheets/application.css +15 -0
- data/spec/rails_4.1_app/app/controllers/application_controller.rb +5 -0
- data/spec/rails_4.1_app/app/controllers/concerns/.keep +0 -0
- data/spec/rails_4.1_app/app/controllers/home_controller.rb +4 -0
- data/spec/rails_4.1_app/app/helpers/application_helper.rb +2 -0
- data/spec/rails_4.1_app/app/mailers/.keep +0 -0
- data/spec/rails_4.1_app/app/models/.keep +0 -0
- data/spec/rails_4.1_app/app/models/concerns/.keep +0 -0
- data/spec/rails_4.1_app/app/models/user.rb +5 -0
- data/spec/rails_4.1_app/app/views/devise/confirmations/new.html.erb +12 -0
- data/spec/rails_4.1_app/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/spec/rails_4.1_app/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/spec/rails_4.1_app/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
- data/spec/rails_4.1_app/app/views/devise/passwords/edit.html.erb +16 -0
- data/spec/rails_4.1_app/app/views/devise/passwords/new.html.erb +12 -0
- data/spec/rails_4.1_app/app/views/devise/registrations/edit.html.erb +29 -0
- data/spec/rails_4.1_app/app/views/devise/registrations/new.html.erb +18 -0
- data/spec/rails_4.1_app/app/views/devise/sessions/new.html.erb +17 -0
- data/spec/rails_4.1_app/app/views/devise/shared/_links.erb +25 -0
- data/spec/rails_4.1_app/app/views/devise/unlocks/new.html.erb +12 -0
- data/spec/rails_4.1_app/app/views/home/index.html.erb +10 -0
- data/spec/rails_4.1_app/app/views/layouts/application.html.erb +17 -0
- data/spec/rails_4.1_app/bin/bundle +3 -0
- data/spec/rails_4.1_app/bin/rails +8 -0
- data/spec/rails_4.1_app/bin/rake +8 -0
- data/spec/rails_4.1_app/bin/spring +18 -0
- data/spec/rails_4.1_app/config.ru +4 -0
- data/spec/rails_4.1_app/config/application.rb +23 -0
- data/spec/rails_4.1_app/config/boot.rb +4 -0
- data/spec/rails_4.1_app/config/database.yml +11 -0
- data/spec/rails_4.1_app/config/environment.rb +5 -0
- data/spec/rails_4.1_app/config/environments/development.rb +37 -0
- data/spec/rails_4.1_app/config/environments/production.rb +83 -0
- data/spec/rails_4.1_app/config/environments/test.rb +39 -0
- data/spec/rails_4.1_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_4.1_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/rails_4.1_app/config/initializers/devise.rb +254 -0
- data/spec/rails_4.1_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/rails_4.1_app/config/initializers/inflections.rb +16 -0
- data/spec/rails_4.1_app/config/initializers/mime_types.rb +5 -0
- data/spec/rails_4.1_app/config/initializers/session_store.rb +5 -0
- data/spec/rails_4.1_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_4.1_app/config/locales/devise.en.yml +59 -0
- data/spec/rails_4.1_app/config/locales/en.yml +23 -0
- data/spec/rails_4.1_app/config/mongo.yml +11 -0
- data/spec/rails_4.1_app/config/mongoid.yml +13 -0
- data/spec/rails_4.1_app/config/routes.rb +4 -0
- data/spec/rails_4.1_app/config/secrets.yml +22 -0
- data/spec/rails_4.1_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
- data/spec/rails_4.1_app/db/schema.rb +25 -0
- data/spec/rails_4.1_app/db/seeds.rb +7 -0
- data/spec/rails_4.1_app/lib/assets/.keep +0 -0
- data/spec/rails_4.1_app/lib/tasks/.keep +0 -0
- data/spec/rails_4.1_app/log/.keep +0 -0
- data/spec/rails_4.1_app/public/404.html +67 -0
- data/spec/rails_4.1_app/public/422.html +67 -0
- data/spec/rails_4.1_app/public/500.html +66 -0
- data/spec/rails_4.1_app/public/favicon.ico +0 -0
- data/spec/rails_4.1_app/public/robots.txt +5 -0
- metadata +264 -12
data/.travis.yml
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
script: "rake"
|
3
3
|
rvm:
|
4
|
-
- 1.8.7
|
5
4
|
- 1.9.3
|
6
5
|
- 2.0.0
|
6
|
+
- 2.1.1
|
7
7
|
- ruby-head
|
8
|
-
- rbx-19mode
|
9
8
|
- jruby-19mode
|
10
9
|
- jruby-head
|
11
10
|
matrix:
|
12
11
|
allow_failures:
|
13
12
|
- rvm: jruby-head
|
14
|
-
- rvm: rbx-19mode
|
15
13
|
- rvm: ruby-head
|
14
|
+
- rvm: rbx
|
16
15
|
services:
|
17
16
|
- mongodb
|
data/Gemfile
CHANGED
@@ -1,39 +1,41 @@
|
|
1
|
-
source
|
2
|
-
|
3
|
-
MONGO_VERS = '1.8.0' unless defined? MONGO_VERS
|
1
|
+
source 'https://rubygems.org'
|
4
2
|
|
5
3
|
RAILS_VERS = case ENV['RAILS_VERS']
|
6
4
|
when '3.1'
|
7
|
-
'~>3.1
|
5
|
+
'~>3.1'
|
8
6
|
when '3.2'
|
9
|
-
'~>3.2
|
7
|
+
'~>3.2'
|
8
|
+
when '4.0'
|
9
|
+
'~>4.0'
|
10
|
+
when '4.1'
|
11
|
+
'~>4.1.0.rc1'
|
10
12
|
when nil
|
11
13
|
nil
|
12
14
|
else
|
13
|
-
raise "Invalid RAILS_VERS. Available versions are 3.
|
15
|
+
raise "Invalid RAILS_VERS. Available versions are 3.2 and 4.0."
|
14
16
|
end
|
15
17
|
|
16
|
-
gemspec
|
18
|
+
gemspec :name => 'mongo_session_store-rails4'
|
17
19
|
|
18
20
|
group :development, :test do
|
19
21
|
gem 'rake'
|
20
|
-
if
|
21
|
-
gem 'mongo_mapper', '>= 0.
|
22
|
+
if ENV['MONGO_SESSION_STORE_ORM'] == 'mongo_mapper'
|
23
|
+
gem 'mongo_mapper', '>= 0.13.0.beta2'
|
22
24
|
end
|
23
25
|
|
24
|
-
if
|
25
|
-
|
26
|
+
if ENV['MONGO_SESSION_STORE_ORM'] == 'mongoid'
|
27
|
+
if ENV['RAILS_VERS'] =~ /4\.\d/
|
28
|
+
gem 'mongoid', '>= 4.0.0.beta1'
|
29
|
+
else
|
30
|
+
gem 'mongoid', '>= 3.1.0'
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
|
-
if
|
29
|
-
gem 'mongo'
|
34
|
+
if ENV['MONGO_SESSION_STORE_ORM'] == 'mongo'
|
35
|
+
gem 'mongo'
|
30
36
|
end
|
31
|
-
gem 'bson_ext', MONGO_VERS, :platforms => :ruby
|
32
37
|
|
33
|
-
gem '
|
34
|
-
gem 'rbx-require-relative', '0.0.5', :platforms => :ruby_18
|
35
|
-
gem 'ruby-debug', :platforms => :ruby_18 unless ENV['TRAVIS']
|
36
|
-
gem 'debugger', :platforms => :ruby_19 unless ENV['TRAVIS']
|
38
|
+
gem 'debugger', :platforms => [:ruby_19, :ruby_20, :ruby_21] unless ENV['TRAVIS']
|
37
39
|
|
38
40
|
if RUBY_PLATFORM == 'java'
|
39
41
|
gem 'jdbc-sqlite3'
|
@@ -45,6 +47,7 @@ group :development, :test do
|
|
45
47
|
gem 'sqlite3' # for devise User storage
|
46
48
|
end
|
47
49
|
RAILS_VERS ? gem('rails', RAILS_VERS) : gem('rails')
|
50
|
+
gem 'minitest' if ENV['RAILS_VERS'] == '4.1'
|
48
51
|
|
49
52
|
gem 'rspec-rails', '2.12.0'
|
50
53
|
gem 'devise'
|
data/README.md
CHANGED
@@ -4,13 +4,17 @@
|
|
4
4
|
|
5
5
|
MongoSessionStore is a collection of Rails-compatible session stores for MongoMapper and Mongoid, but also included is a generic Mongo store that works with any (or no!) Mongo ODM.
|
6
6
|
|
7
|
-
MongoSessionStore is tested [on Travis CI](https://travis-ci.org/brianhempel/mongo_session_store) against Ruby 1.
|
7
|
+
MongoSessionStore is tested [on Travis CI](https://travis-ci.org/brianhempel/mongo_session_store) against Ruby 1.9.3, 2.0.0, 2.1.1, and JRuby with Rails 3.1 through 4.1.
|
8
|
+
|
9
|
+
Mongoid users: This gem is compatible with both Mongoid 3 and 4.
|
8
10
|
|
9
11
|
If this gem doesn't work for you, you might next try [mongo_sessions](https://github.com/biilmann/mongo_sessions).
|
10
12
|
|
13
|
+
See the [Changelog](#changelog) if you need support for an older version of Ruby, Rails, or Mongoid.
|
14
|
+
|
11
15
|
## Usage
|
12
16
|
|
13
|
-
MongoSessionStore is compatible with Rails 3.1
|
17
|
+
MongoSessionStore is compatible with Rails 3.1 through 4.1.
|
14
18
|
|
15
19
|
In your Gemfile:
|
16
20
|
|
@@ -18,7 +22,8 @@ In your Gemfile:
|
|
18
22
|
gem "mongo_mapper"
|
19
23
|
# or gem "mongoid"
|
20
24
|
# or gem "mongo"
|
21
|
-
gem "mongo_session_store-
|
25
|
+
gem "mongo_session_store-rails4"
|
26
|
+
# or gem "mongo_session_store-rails3"
|
22
27
|
```
|
23
28
|
|
24
29
|
In the session_store initializer (config/initializers/session_store.rb):
|
@@ -35,8 +40,6 @@ MyApp::Application.config.session_store :mongo_store
|
|
35
40
|
MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')
|
36
41
|
```
|
37
42
|
|
38
|
-
Note: If you choose to use `:mongo_store` you only need to set its database if you aren't using MongoMapper or Mongoid in your project.
|
39
|
-
|
40
43
|
By default, the sessions will be stored in the "sessions" collection in MongoDB. If you want to use a different collection, you can set that in the initializer:
|
41
44
|
|
42
45
|
```ruby
|
@@ -56,34 +59,13 @@ MongoidStore::Session.where(:updated_at.gt => 2.days.ago)
|
|
56
59
|
MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })
|
57
60
|
```
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
The
|
64
|
-
|
65
|
-
|
66
|
-
MongoMapperStore...
|
67
|
-
3.65ms per session save
|
68
|
-
2.25ms per session load
|
69
|
-
Total Size: 23648924
|
70
|
-
Object count: 2000
|
71
|
-
Average object size: 11824.462
|
72
|
-
Index sizes: {"_id_"=>172032}
|
73
|
-
MongoidStore...
|
74
|
-
2.59ms per session save
|
75
|
-
1.33ms per session load
|
76
|
-
Total Size: 23648924
|
77
|
-
Object count: 2000
|
78
|
-
Average object size: 11824.462
|
79
|
-
Index sizes: {"_id_"=>172032}
|
80
|
-
MongoStore...
|
81
|
-
1.42ms per session save
|
82
|
-
1.11ms per session load
|
83
|
-
Total Size: 23648924
|
84
|
-
Object count: 2000
|
85
|
-
Average object size: 11824.462
|
86
|
-
Index sizes: {"_id_"=>204800}
|
62
|
+
## Changelog
|
63
|
+
|
64
|
+
5.0.0 introduces Rails 4.0 and 4.1 support and Mongoid 4 support alongside the existing Rails 3.1, 3.2, and Mongoid 3 support. Ruby 1.8.7 support is dropped. The database is no longer set automatically for the MongoStore when MongoMapper or Mongoid is present. You have to set the database manually whenever you choose to use the vanilla MongoStore.
|
65
|
+
|
66
|
+
The last version to support Ruby 1.8.7 is [version 4.1.1](https://rubygems.org/gems/mongo_session_store-rails3/versions/4.1.1).
|
67
|
+
|
68
|
+
The last version to support Rails 3.0 or Mongoid 2 is [version 3.0.6](https://rubygems.org/gems/mongo_session_store-rails3/versions/3.0.6).
|
87
69
|
|
88
70
|
## Development
|
89
71
|
|
@@ -91,16 +73,16 @@ To run all the tests:
|
|
91
73
|
|
92
74
|
rake
|
93
75
|
|
94
|
-
To
|
76
|
+
To run the tests for a specific store (examples):
|
95
77
|
|
96
|
-
rake
|
97
|
-
rake
|
78
|
+
rake test_31_mongo
|
79
|
+
rake test_32_mongoid
|
80
|
+
rake test_40_mongoid
|
81
|
+
rake test_41_mongo_mapper
|
98
82
|
|
99
|
-
To
|
83
|
+
To see a list of all options for running tests, run
|
100
84
|
|
101
|
-
|
102
|
-
MONGO_SESSION_STORE_ORM=mongoid bundle exec rspec spec
|
103
|
-
MONGO_SESSION_STORE_ORM=mongo bundle exec rspec spec
|
85
|
+
rake -T
|
104
86
|
|
105
87
|
## Previous contributors
|
106
88
|
|
@@ -115,7 +97,7 @@ MongoSessionStore started as a fork of the DataMapper session store, modified to
|
|
115
97
|
|
116
98
|
## License
|
117
99
|
|
118
|
-
Copyright (c) 2011-
|
100
|
+
Copyright (c) 2011-2014 Brian Hempel
|
119
101
|
Copyright (c) 2010 Nicolas Mérouze
|
120
102
|
Copyright (c) 2009 Chris Brickley
|
121
103
|
Copyright (c) 2009 Tony Pitale
|
data/Rakefile
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require 'bundler'
|
4
|
-
Bundler::GemHelper.install_tasks
|
4
|
+
Bundler::GemHelper.install_tasks :name => 'mongo_session_store-rails3'
|
5
5
|
|
6
6
|
def run_with_output(command)
|
7
7
|
puts "Running: #{command}"
|
8
8
|
system(command)
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
run_with_output
|
11
|
+
def set_versions(rails_vers, orm)
|
12
|
+
success = true
|
13
|
+
unless File.exists?("Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock")
|
14
|
+
success &&= run_with_output("export RAILS_VERS=#{rails_vers}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle update")
|
15
|
+
success &&= run_with_output("cp Gemfile.lock Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock")
|
15
16
|
else
|
16
|
-
run_with_output
|
17
|
-
run_with_output
|
17
|
+
success &&= run_with_output("rm Gemfile.lock")
|
18
|
+
success &&= run_with_output("cp Gemfile_Rails_#{rails_vers}_#{orm}_#{RUBY_VERSION}.lock Gemfile.lock")
|
18
19
|
end
|
20
|
+
success
|
19
21
|
end
|
20
22
|
|
21
|
-
@rails_versions = ['3.1', '3.2']
|
23
|
+
@rails_versions = ['3.1', '3.2', '4.0', '4.1']
|
24
|
+
@orms = ['mongo_mapper', 'mongoid', 'mongo']
|
22
25
|
|
23
26
|
task :default => :test_all
|
24
27
|
|
25
|
-
desc 'Test each session store against Rails 3.1 and
|
28
|
+
desc 'Test each session store against Rails 3.1, 3.2, 4.0, and 4.1'
|
26
29
|
task :test_all do
|
27
30
|
# inspired by http://pivotallabs.com/users/jdean/blog/articles/1728-testing-your-gem-against-multiple-rubies-and-rails-versions-with-rvm
|
28
31
|
|
29
|
-
orms = ['mongo_mapper', 'mongoid', 'mongo']
|
30
|
-
orms.delete('mongoid') if RUBY_VERSION < "1.9"
|
31
32
|
|
32
33
|
@failed_suites = []
|
33
34
|
|
34
35
|
@rails_versions.each do |rails_version|
|
36
|
+
@orms.each do |orm|
|
37
|
+
success = set_versions(rails_version, orm)
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
orms.each do |orm|
|
39
|
-
unless run_with_output "export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec"
|
39
|
+
unless success && run_with_output("export RAILS_VERS=#{rails_version}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec")
|
40
40
|
@failed_suites << "Rails #{rails_version} / #{orm}"
|
41
41
|
end
|
42
42
|
end
|
@@ -54,13 +54,24 @@ task :test_all do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
57
|
@rails_versions.each do |rails_version|
|
58
|
+
@orms.each do |orm|
|
59
|
+
desc "Set Gemfile.lock to #{rails_version} with #{orm}"
|
60
|
+
task :"use_#{rails_version.gsub('.', '')}_#{orm}" do
|
61
|
+
set_versions(rails_version, orm)
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
64
|
+
desc "Test against #{rails_version} with #{orm}"
|
65
|
+
task :"test_#{rails_version.gsub('.', '')}_#{orm}" do
|
66
|
+
set_versions(rails_version, orm)
|
67
|
+
success = run_with_output("export RAILS_VERS=#{rails_version}; export MONGO_SESSION_STORE_ORM=#{orm}; bundle exec rspec spec")
|
68
|
+
exit(1) unless success
|
69
|
+
end
|
65
70
|
|
71
|
+
desc "Rebundle for #{rails_version} with #{orm}"
|
72
|
+
task :"rebundle_#{rails_version.gsub('.', '')}_#{orm}" do
|
73
|
+
run_with_output "rm Gemfile_Rails_#{rails_version}_#{orm}_#{RUBY_VERSION}.lock Gemfile.lock"
|
74
|
+
set_versions(rails_version, orm)
|
75
|
+
end
|
76
|
+
end
|
66
77
|
end
|
@@ -1,50 +1 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
$:.unshift File.dirname(__FILE__)
|
4
|
-
|
5
|
-
module MongoSessionStore
|
6
|
-
autoload :VERSION, 'mongo_session_store/version'
|
7
|
-
|
8
|
-
def self.collection_name=(name)
|
9
|
-
@collection_name = name
|
10
|
-
|
11
|
-
if defined?(MongoStore::Session)
|
12
|
-
MongoStore::Session.reset_collection
|
13
|
-
end
|
14
|
-
|
15
|
-
if defined?(MongoMapperStore::Session)
|
16
|
-
MongoMapperStore::Session.set_collection_name(name)
|
17
|
-
end
|
18
|
-
|
19
|
-
if defined?(MongoidStore::Session)
|
20
|
-
|
21
|
-
MongoidStore::Session.store_in :collection => MongoSessionStore.collection_name
|
22
|
-
end
|
23
|
-
|
24
|
-
@collection_name
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.collection_name
|
28
|
-
@collection_name
|
29
|
-
end
|
30
|
-
|
31
|
-
# default collection name for all the stores
|
32
|
-
self.collection_name = "sessions"
|
33
|
-
end
|
34
|
-
|
35
|
-
# we don't use autoloading because of thread concerns
|
36
|
-
# hence, this mess
|
37
|
-
load_errors = []
|
38
|
-
|
39
|
-
%w(mongo_mapper_store mongoid_store mongo_store).each do |store_name|
|
40
|
-
begin
|
41
|
-
require "mongo_session_store/#{store_name}"
|
42
|
-
rescue LoadError => e
|
43
|
-
load_errors << e
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
if load_errors.count == 3
|
48
|
-
message = "Could not load any session store!\n" + load_errors.map(&:message).join("\n")
|
49
|
-
raise LoadError, message
|
50
|
-
end
|
1
|
+
require 'mongo_session_store'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mongo_session_store'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
module MongoSessionStore
|
6
|
+
autoload :VERSION, 'mongo_session_store/version'
|
7
|
+
|
8
|
+
def self.collection_name=(name)
|
9
|
+
@collection_name = name
|
10
|
+
|
11
|
+
if defined?(MongoStore::Session)
|
12
|
+
MongoStore::Session.reset_collection
|
13
|
+
end
|
14
|
+
|
15
|
+
if defined?(MongoMapperStore::Session)
|
16
|
+
MongoMapperStore::Session.set_collection_name(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined?(MongoidStore::Session)
|
20
|
+
MongoidStore::Session.store_in :collection => MongoSessionStore.collection_name
|
21
|
+
end
|
22
|
+
|
23
|
+
@collection_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.collection_name
|
27
|
+
@collection_name
|
28
|
+
end
|
29
|
+
|
30
|
+
# default collection name for all the stores
|
31
|
+
self.collection_name = "sessions"
|
32
|
+
end
|
33
|
+
|
34
|
+
# we don't use autoloading because of thread concerns
|
35
|
+
# hence, this mess
|
36
|
+
load_errors = []
|
37
|
+
|
38
|
+
%w(mongo_mapper_store mongoid_store mongo_store).each do |store_name|
|
39
|
+
begin
|
40
|
+
require "mongo_session_store/#{store_name}"
|
41
|
+
rescue LoadError => e
|
42
|
+
load_errors << e
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if load_errors.count == 3
|
47
|
+
message = "Could not load any session store!\n" + load_errors.map(&:message).join("\n")
|
48
|
+
raise LoadError, message
|
49
|
+
end
|
@@ -50,10 +50,6 @@ module ActionDispatch
|
|
50
50
|
def self.database
|
51
51
|
if @database
|
52
52
|
@database
|
53
|
-
elsif defined?(MongoMapper)
|
54
|
-
MongoMapper.database
|
55
|
-
elsif defined?(Mongoid)
|
56
|
-
Mongoid.database
|
57
53
|
else
|
58
54
|
raise "MongoStore needs a database, e.g. MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')"
|
59
55
|
end
|
@@ -4,6 +4,7 @@ require 'mongo_session_store/mongo_store_base'
|
|
4
4
|
module ActionDispatch
|
5
5
|
module Session
|
6
6
|
class MongoidStore < MongoStoreBase
|
7
|
+
BINARY_CLASS = defined?(Moped::BSON::Binary) ? Moped::BSON::Binary : BSON::Binary
|
7
8
|
|
8
9
|
class Session
|
9
10
|
include Mongoid::Document
|
@@ -12,15 +13,38 @@ module ActionDispatch
|
|
12
13
|
store_in :collection => MongoSessionStore.collection_name
|
13
14
|
|
14
15
|
field :_id, :type => String
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
field :data, :type => BINARY_CLASS, :default => -> { marshaled_binary({}) }
|
17
|
+
attr_accessible :_id, :data if respond_to?(:attr_accessible)
|
18
|
+
|
19
|
+
def marshaled_binary(data)
|
20
|
+
self.class.marshaled_binary(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.marshaled_binary(data)
|
24
|
+
if BINARY_CLASS.to_s == 'BSON::Binary'
|
25
|
+
BSON::Binary.new(Marshal.dump(data), :generic)
|
26
|
+
else
|
27
|
+
Moped::BSON::Binary.new(:generic, Marshal.dump(data))
|
28
|
+
end
|
29
|
+
end
|
19
30
|
end
|
20
31
|
|
21
32
|
private
|
22
33
|
def pack(data)
|
23
|
-
|
34
|
+
session_class.marshaled_binary(data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def unpack(packed)
|
38
|
+
return nil unless packed
|
39
|
+
Marshal.load(extract_data(packed))
|
40
|
+
end
|
41
|
+
|
42
|
+
def extract_data(packed)
|
43
|
+
if packed.class.to_s == 'BSON::Binary'
|
44
|
+
packed.data
|
45
|
+
else
|
46
|
+
packed.to_s
|
47
|
+
end
|
24
48
|
end
|
25
49
|
end
|
26
50
|
end
|