mongo_session_store-rails 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +44 -0
  5. data/.travis.yml +29 -0
  6. data/Gemfile +3 -0
  7. data/README.md +144 -0
  8. data/Rakefile +87 -0
  9. data/gemfiles/rails-4.0-mongo.gemfile +9 -0
  10. data/gemfiles/rails-4.0-mongoid.gemfile +9 -0
  11. data/gemfiles/rails-4.1-mongo.gemfile +9 -0
  12. data/gemfiles/rails-4.1-mongoid.gemfile +9 -0
  13. data/gemfiles/rails-4.2-mongo.gemfile +9 -0
  14. data/gemfiles/rails-4.2-mongoid.gemfile +9 -0
  15. data/lib/mongo_session_store-rails.rb +1 -0
  16. data/lib/mongo_session_store.rb +27 -0
  17. data/lib/mongo_session_store/mongo_store.rb +102 -0
  18. data/lib/mongo_session_store/mongo_store_base.rb +69 -0
  19. data/lib/mongo_session_store/mongoid_store.rb +47 -0
  20. data/lib/mongo_session_store/version.rb +3 -0
  21. data/mongo_session_store.gemspec +22 -0
  22. data/perf/benchmark.rb +99 -0
  23. data/spec/.rubocop.yml +4 -0
  24. data/spec/integrations/devise_spec.rb +109 -0
  25. data/spec/lib/mongo_session_store/mongo_store/session_spec.rb +250 -0
  26. data/spec/lib/mongo_session_store/mongo_store_base_spec.rb +269 -0
  27. data/spec/lib/mongo_session_store/mongo_store_spec.rb +13 -0
  28. data/spec/lib/mongo_session_store/mongoid_store/session_spec.rb +67 -0
  29. data/spec/lib/mongo_session_store/mongoid_store_spec.rb +13 -0
  30. data/spec/lib/mongo_session_store_spec.rb +64 -0
  31. data/spec/rails_helper.rb +19 -0
  32. data/spec/spec_helper.rb +44 -0
  33. data/spec/support/apps/rails_4.0_app/Rakefile +6 -0
  34. data/spec/support/apps/rails_4.0_app/app/controllers/application_controller.rb +5 -0
  35. data/spec/support/apps/rails_4.0_app/app/controllers/home_controller.rb +4 -0
  36. data/spec/support/apps/rails_4.0_app/app/models/user.rb +5 -0
  37. data/spec/support/apps/rails_4.0_app/app/views/home/index.html.erb +10 -0
  38. data/spec/support/apps/rails_4.0_app/app/views/layouts/application.html.erb +17 -0
  39. data/spec/support/apps/rails_4.0_app/bin/bundle +3 -0
  40. data/spec/support/apps/rails_4.0_app/bin/rails +4 -0
  41. data/spec/support/apps/rails_4.0_app/bin/rake +4 -0
  42. data/spec/support/apps/rails_4.0_app/config.ru +4 -0
  43. data/spec/support/apps/rails_4.0_app/config/application.rb +11 -0
  44. data/spec/support/apps/rails_4.0_app/config/boot.rb +4 -0
  45. data/spec/support/apps/rails_4.0_app/config/database.yml +11 -0
  46. data/spec/support/apps/rails_4.0_app/config/environment.rb +5 -0
  47. data/spec/support/apps/rails_4.0_app/config/environments/development.rb +12 -0
  48. data/spec/support/apps/rails_4.0_app/config/environments/test.rb +19 -0
  49. data/spec/support/apps/rails_4.0_app/config/initializers/devise.rb +254 -0
  50. data/spec/support/apps/rails_4.0_app/config/initializers/secret_token.rb +12 -0
  51. data/spec/support/apps/rails_4.0_app/config/initializers/session_store.rb +1 -0
  52. data/spec/support/apps/rails_4.0_app/config/locales/devise.en.yml +59 -0
  53. data/spec/support/apps/rails_4.0_app/config/locales/en.yml +23 -0
  54. data/spec/support/apps/rails_4.0_app/config/mongo.yml +11 -0
  55. data/spec/support/apps/rails_4.0_app/config/mongoid.yml +13 -0
  56. data/spec/support/apps/rails_4.0_app/config/routes.rb +4 -0
  57. data/spec/support/apps/rails_4.0_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  58. data/spec/support/apps/rails_4.0_app/db/schema.rb +25 -0
  59. data/spec/support/apps/rails_4.0_app/db/seeds.rb +7 -0
  60. data/spec/support/apps/rails_4.0_app/lib/assets/.keep +0 -0
  61. data/spec/support/apps/rails_4.0_app/lib/tasks/.keep +0 -0
  62. data/spec/support/apps/rails_4.0_app/log/.keep +0 -0
  63. data/spec/support/apps/rails_4.0_app/public/404.html +58 -0
  64. data/spec/support/apps/rails_4.0_app/public/422.html +58 -0
  65. data/spec/support/apps/rails_4.0_app/public/500.html +57 -0
  66. data/spec/support/apps/rails_4.0_app/public/favicon.ico +0 -0
  67. data/spec/support/apps/rails_4.0_app/public/robots.txt +5 -0
  68. data/spec/support/apps/rails_4.1_app/Rakefile +3 -0
  69. data/spec/support/apps/rails_4.1_app/app/controllers/application_controller.rb +5 -0
  70. data/spec/support/apps/rails_4.1_app/app/controllers/home_controller.rb +4 -0
  71. data/spec/support/apps/rails_4.1_app/app/models/user.rb +5 -0
  72. data/spec/support/apps/rails_4.1_app/app/views/home/index.html.erb +10 -0
  73. data/spec/support/apps/rails_4.1_app/app/views/layouts/application.html.erb +17 -0
  74. data/spec/support/apps/rails_4.1_app/bin/bundle +3 -0
  75. data/spec/support/apps/rails_4.1_app/bin/rails +4 -0
  76. data/spec/support/apps/rails_4.1_app/bin/rake +4 -0
  77. data/spec/support/apps/rails_4.1_app/config.ru +2 -0
  78. data/spec/support/apps/rails_4.1_app/config/application.rb +11 -0
  79. data/spec/support/apps/rails_4.1_app/config/boot.rb +4 -0
  80. data/spec/support/apps/rails_4.1_app/config/database.yml +11 -0
  81. data/spec/support/apps/rails_4.1_app/config/environment.rb +5 -0
  82. data/spec/support/apps/rails_4.1_app/config/environments/development.rb +12 -0
  83. data/spec/support/apps/rails_4.1_app/config/environments/test.rb +19 -0
  84. data/spec/support/apps/rails_4.1_app/config/initializers/devise.rb +254 -0
  85. data/spec/support/apps/rails_4.1_app/config/initializers/session_store.rb +1 -0
  86. data/spec/support/apps/rails_4.1_app/config/locales/devise.en.yml +59 -0
  87. data/spec/support/apps/rails_4.1_app/config/locales/en.yml +23 -0
  88. data/spec/support/apps/rails_4.1_app/config/mongo.yml +11 -0
  89. data/spec/support/apps/rails_4.1_app/config/mongoid.yml +13 -0
  90. data/spec/support/apps/rails_4.1_app/config/routes.rb +4 -0
  91. data/spec/support/apps/rails_4.1_app/config/secrets.yml +22 -0
  92. data/spec/support/apps/rails_4.1_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  93. data/spec/support/apps/rails_4.1_app/db/schema.rb +25 -0
  94. data/spec/support/apps/rails_4.1_app/db/seeds.rb +7 -0
  95. data/spec/support/apps/rails_4.1_app/lib/assets/.keep +0 -0
  96. data/spec/support/apps/rails_4.1_app/lib/tasks/.keep +0 -0
  97. data/spec/support/apps/rails_4.1_app/log/.keep +0 -0
  98. data/spec/support/apps/rails_4.1_app/public/404.html +67 -0
  99. data/spec/support/apps/rails_4.1_app/public/422.html +67 -0
  100. data/spec/support/apps/rails_4.1_app/public/500.html +66 -0
  101. data/spec/support/apps/rails_4.1_app/public/favicon.ico +0 -0
  102. data/spec/support/apps/rails_4.1_app/public/robots.txt +5 -0
  103. data/spec/support/apps/rails_4.2_app/Rakefile +2 -0
  104. data/spec/support/apps/rails_4.2_app/app/controllers/application_controller.rb +5 -0
  105. data/spec/support/apps/rails_4.2_app/app/controllers/home_controller.rb +4 -0
  106. data/spec/support/apps/rails_4.2_app/app/models/user.rb +5 -0
  107. data/spec/support/apps/rails_4.2_app/app/views/home/index.html.erb +10 -0
  108. data/spec/support/apps/rails_4.2_app/app/views/layouts/application.html.erb +15 -0
  109. data/spec/support/apps/rails_4.2_app/bin/bundle +3 -0
  110. data/spec/support/apps/rails_4.2_app/bin/rails +8 -0
  111. data/spec/support/apps/rails_4.2_app/bin/rake +4 -0
  112. data/spec/support/apps/rails_4.2_app/config.ru +4 -0
  113. data/spec/support/apps/rails_4.2_app/config/application.rb +11 -0
  114. data/spec/support/apps/rails_4.2_app/config/boot.rb +3 -0
  115. data/spec/support/apps/rails_4.2_app/config/database.yml +11 -0
  116. data/spec/support/apps/rails_4.2_app/config/environment.rb +5 -0
  117. data/spec/support/apps/rails_4.2_app/config/environments/development.rb +12 -0
  118. data/spec/support/apps/rails_4.2_app/config/environments/test.rb +19 -0
  119. data/spec/support/apps/rails_4.2_app/config/initializers/devise.rb +254 -0
  120. data/spec/support/apps/rails_4.2_app/config/initializers/session_store.rb +1 -0
  121. data/spec/support/apps/rails_4.2_app/config/locales/en.yml +23 -0
  122. data/spec/support/apps/rails_4.2_app/config/mongo.yml +11 -0
  123. data/spec/support/apps/rails_4.2_app/config/mongoid.yml +13 -0
  124. data/spec/support/apps/rails_4.2_app/config/routes.rb +4 -0
  125. data/spec/support/apps/rails_4.2_app/config/secrets.yml +22 -0
  126. data/spec/support/apps/rails_4.2_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
  127. data/spec/support/apps/rails_4.2_app/db/schema.rb +25 -0
  128. data/spec/support/apps/rails_4.2_app/db/seeds.rb +7 -0
  129. data/spec/support/helpers/test_database_helper.rb +22 -0
  130. metadata +367 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fae6c0b168c889f3ddc4cdde51ba533c186a3cc6
4
+ data.tar.gz: 6a7734c7e98396f397ca7e365a46639536bf056a
5
+ SHA512:
6
+ metadata.gz: 88a8e26cc229350d17101cdc2d9e7ca2b43b6b0ff37d076b7e14fadfe4b165da6a70724a32baccec3d36eea25195c31a2b5a5e28c259335d01b8554809915eab
7
+ data.tar.gz: 54ebfe5d1f4a1db26444f7d5748740d960a4e3828d79504e1b313ec08ffa79c2889c8a23ecdc2b88f07920e488a6ef5cbf58e4601a50310dbf2dd5dd70b87016
@@ -0,0 +1,8 @@
1
+ /doc
2
+ /coverage
3
+ Gemfile.lock
4
+ gemfiles/*.lock
5
+ spec/support/apps/rails_*/tmp/
6
+ spec/support/apps/rails_*/db/*.sqlite3
7
+ *.gem
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,44 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.0
3
+ Include:
4
+ - "Gemfile"
5
+ Exclude:
6
+ - "lib/mongo_session_store-rails.rb"
7
+ - "gemfiles/vendor/**/*"
8
+ - "perf/benchmark.rb"
9
+ - "spec/support/apps/**/*"
10
+ - "tmp/**/*"
11
+ - "vendor/**/*"
12
+ DisplayCopNames: true
13
+ UseCache: true
14
+ CacheRootDirectory: ./tmp
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/StringLiterals:
20
+ EnforcedStyle: double_quotes
21
+
22
+ Style/StringLiteralsInInterpolation:
23
+ EnforcedStyle: double_quotes
24
+
25
+ Style/AlignParameters:
26
+ EnforcedStyle: with_fixed_indentation
27
+
28
+ Style/MultilineOperationIndentation:
29
+ EnforcedStyle: indented
30
+
31
+ Style/AlignHash:
32
+ EnforcedLastArgumentHashStyle: ignore_implicit
33
+
34
+ Style/HashSyntax:
35
+ EnforcedStyle: hash_rockets
36
+
37
+ Style/IndentArray:
38
+ EnforcedStyle: consistent
39
+
40
+ Style/FormatString:
41
+ EnforcedStyle: sprintf
42
+
43
+ Metrics/MethodLength:
44
+ Max: 15
@@ -0,0 +1,29 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - "2.0.0"
5
+ - "2.1.0"
6
+ - "2.2.0"
7
+ - "2.3.0"
8
+ gemfile:
9
+ - "gemfiles/rails-4.0-mongo.gemfile"
10
+ - "gemfiles/rails-4.0-mongoid.gemfile"
11
+ - "gemfiles/rails-4.1-mongo.gemfile"
12
+ - "gemfiles/rails-4.1-mongoid.gemfile"
13
+ - "gemfiles/rails-4.2-mongo.gemfile"
14
+ - "gemfiles/rails-4.2-mongoid.gemfile"
15
+ matrix:
16
+ fast_finish: true
17
+ include:
18
+ - rvm: "2.3.0"
19
+ gemfile: "gemfiles/rails-4.2-mongo.gemfile"
20
+ script: "bundle exec rubocop"
21
+
22
+ before_script:
23
+ - wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.1.tgz -O /tmp/mongodb.tgz
24
+ - tar -xvf /tmp/mongodb.tgz
25
+ - mkdir /tmp/data
26
+ - ${PWD}/mongodb-linux-x86_64-3.0.1/bin/mongod --dbpath /tmp/data --bind_ip 127.0.0.1 &> /dev/null &
27
+
28
+ script:
29
+ - "bundle exec rake test"
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,144 @@
1
+ # MongoSessionStore
2
+
3
+ [![Build Status](https://travis-ci.org/appsignal/mongo_session_store.png?branch=master)](https://travis-ci.org/appsignal/mongo_session_store) [![Gem Version](https://badge.fury.io/rb/mongo_session_store-rails.svg)](http://badge.fury.io/rb/mongo_session_store-rails)
4
+
5
+ ## Description
6
+
7
+ MongoSessionStore is a Rails-compatible session store for Mongo using either
8
+ Mongoid or the Ruby MongoDB driver. It also allows for custom Mongo session
9
+ store that works with any (or no!) Mongo ODM.
10
+
11
+ ## Usage
12
+
13
+ MongoSessionStore is compatible with Rails 4.0 through 4.2.
14
+
15
+ In your Gemfile:
16
+
17
+ ```ruby
18
+ gem "mongoid"
19
+ # or gem "mongo"
20
+ gem "mongo_session_store-rails"
21
+ ```
22
+
23
+ In the session_store initializer:
24
+
25
+ ```ruby
26
+ # config/initializers/session_store.rb
27
+
28
+ # Mongoid
29
+ MyApp::Application.config.session_store :mongoid_store
30
+
31
+ # anything else
32
+ MongoStore::Session.database = Mongo::Client.new(["127.0.0.1:27017"], database: "my_app_development")
33
+ MyApp::Application.config.session_store :mongo_store
34
+ ```
35
+
36
+ By default, the sessions will be stored in the "sessions" collection in
37
+ MongoDB. If you want to use a different collection, you can set that in the
38
+ initializer:
39
+
40
+ ```ruby
41
+ # config/initializers/session_store.rb
42
+ MongoSessionStore.collection_name = "client_sessions"
43
+ ```
44
+
45
+ And if you want to query your sessions:
46
+
47
+ ```ruby
48
+ # Mongoid
49
+ MongoidStore::Session.where(:updated_at.gt => 2.days.ago)
50
+
51
+ # Plain old Mongo
52
+ MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })
53
+ ```
54
+
55
+ ## Changelog
56
+
57
+ 7.0.0 Drops explicit MongoMapper support, but can be readded manually with a
58
+ custom session class. Drops explicit JRuby support. Moved session data packing
59
+ and unpacking to the session models themselves. Adds more tests to internals.
60
+
61
+ 6.0.0 supports the Mongo Ruby Driver 2.0 for the generic MongoStore. The other
62
+ stores are unchanged. Tests added for Rails 4.2. Tests against MongoDB 3.0.1 on
63
+ Travis CI.
64
+
65
+ 5.1.0 generates a new session ID when a session is not found. Previously, when
66
+ a session ID is provided in the request but the session was not found (because
67
+ for example, it was removed from Mongo by a sweeper job) a new session with the
68
+ provided ID would be created. This would cause a write error if two
69
+ simultaneous requests both create a session with the same ID and both try to
70
+ insert a new document with that ID.
71
+
72
+ 5.0.1 suppresses a warning from Mongoid 4 when setting the _id field type to
73
+ String.
74
+
75
+ 5.0.0 introduces Rails 4.0 and 4.1 support and Mongoid 4 support alongside the
76
+ existing Rails 3.1, 3.2, and Mongoid 3 support. Ruby 1.8.7 support is dropped.
77
+ The database is no longer set automatically for the MongoStore when MongoMapper
78
+ or Mongoid is present. You have to set the database manually whenever you
79
+ choose to use the vanilla MongoStore.
80
+
81
+ The last version to support Ruby 1.8.7 is [version
82
+ 4.1.1](https://rubygems.org/gems/mongo_session_store-rails3/versions/4.1.1).
83
+
84
+ The last version to support Rails 3.0 or Mongoid 2 is [version
85
+ 3.0.6](https://rubygems.org/gems/mongo_session_store-rails3/versions/3.0.6).
86
+
87
+ ## Development
88
+
89
+ To run all the tests:
90
+
91
+ ```sh
92
+ rake
93
+ ```
94
+
95
+ To run the tests for a specific store:
96
+
97
+ ```sh
98
+ BUNDLE_GEMFILE=gemfiles/rails-4.0-mongo.gemfile bundle exec rake
99
+ BUNDLE_GEMFILE=gemfiles/rails-4.0-mongoid.gemfile bundle exec rake
100
+ BUNDLE_GEMFILE=gemfiles/rails-4.1-mongo.gemfile bundle exec rake
101
+ BUNDLE_GEMFILE=gemfiles/rails-4.1-mongoid.gemfile bundle exec rake
102
+ BUNDLE_GEMFILE=gemfiles/rails-4.2-mongo.gemfile bundle exec rake
103
+ BUNDLE_GEMFILE=gemfiles/rails-4.2-mongoid.gemfile bundle exec rake
104
+ ```
105
+
106
+ ## Previous contributors
107
+
108
+ MongoSessionStore started as a fork of the DataMapper session store, modified
109
+ to work with MongoMapper and Mongoid. Much thanks to all the previous
110
+ contributors:
111
+
112
+ * Nicolas Mérouze
113
+ * Chris Brickley
114
+ * Tony Pitale
115
+ * Nicola Racco
116
+ * Matt Powell
117
+ * Ryan Fitzgerald
118
+ * Brian Hempel
119
+
120
+ ## License
121
+
122
+ Copyright (c) 2016 Tom de Bruijn
123
+ Copyright (c) 2011-2015 Brian Hempel
124
+ Copyright (c) 2010 Nicolas Mérouze
125
+ Copyright (c) 2009 Chris Brickley
126
+ Copyright (c) 2009 Tony Pitale
127
+
128
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
129
+ this software and associated documentation files (the "Software"), to deal in
130
+ the Software without restriction, including without limitation the rights to
131
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
132
+ of the Software, and to permit persons to whom the Software is furnished to do
133
+ so, subject to the following conditions:
134
+
135
+ The above copyright notice and this permission notice shall be included in all
136
+ copies or substantial portions of the Software.
137
+
138
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
139
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
140
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
141
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
142
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
143
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
144
+ SOFTWARE.
@@ -0,0 +1,87 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ task :mongo_prepare do
4
+ # Wait for mongod to start on Travis.
5
+ # From the Mongo Ruby Driver gem.
6
+ if ENV["TRAVIS"]
7
+ require "mongo"
8
+ client = Mongo::Client.new(["127.0.0.1:27017"])
9
+ begin
10
+ puts "Waiting for MongoDB..."
11
+ client.command("ismaster" => 1)
12
+ rescue Mongo::Error::NoServerAvailable => e
13
+ sleep(2)
14
+ # 1 Retry
15
+ puts "Waiting for MongoDB..."
16
+ client.cluster.scan!
17
+ client.command(Mongo::Error::NoServerAvailable)
18
+ end
19
+ end
20
+ end
21
+
22
+ desc "Run the mongo_session_store gem test suite."
23
+ RSpec::Core::RakeTask.new :test => :mongo_prepare
24
+
25
+ task :release do
26
+ GEMSPEC_NAME = "mongo_session_store"
27
+ GEM_NAME = "mongo_session_store-rails"
28
+ VERSION_FILE = "lib/mongo_session_store/version.rb"
29
+
30
+ def reload_version
31
+ if defined?(MongoSessionStore::VERSION)
32
+ MongoSessionStore.send(:remove_const, :VERSION)
33
+ end
34
+ load File.expand_path(VERSION_FILE)
35
+ end
36
+
37
+ raise "$EDITOR should be set" unless ENV["EDITOR"]
38
+
39
+ def build_and_push_gem
40
+ puts '# Building gem'
41
+ puts `gem build #{GEMSPEC_NAME}.gemspec`
42
+ puts '# Publishing Gem'
43
+ puts `gem push #{GEM_NAME}-#{gem_version}.gem`
44
+ end
45
+
46
+ def update_repo
47
+ puts `git commit -am "Bump to #{version} [ci skip]"`
48
+ begin
49
+ puts `git tag #{version}`
50
+ puts `git push origin #{version}`
51
+ puts `git push origin master`
52
+ rescue
53
+ raise %(Tag: "#{version}" already exists)
54
+ end
55
+ end
56
+
57
+ def changes
58
+ git_status_to_array(`git status -s -u`)
59
+ end
60
+
61
+ def gem_version
62
+ MongoSessionStore::VERSION
63
+ end
64
+
65
+ def version
66
+ @version ||= "v" << gem_version
67
+ end
68
+
69
+ def git_status_to_array(changes)
70
+ changes.split("\n").map { |change| change.gsub(/^.. /, "") }
71
+ end
72
+
73
+ raise "Branch should hold no uncommitted file change)" unless changes.empty?
74
+
75
+ reload_version
76
+
77
+ system("$EDITOR #{VERSION_FILE}")
78
+ if changes.include?(VERSION_FILE)
79
+ reload_version
80
+ build_and_push_gem
81
+ update_repo
82
+ else
83
+ raise "Actually change the version in: #{VERSION_FILE}"
84
+ end
85
+ end
86
+
87
+ task :default => :test
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongo"
4
+
5
+ gem "rails", "4.0"
6
+ gem "devise", "~> 3.5"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid"
4
+
5
+ gem "rails", "4.0"
6
+ gem "devise", "~> 3.5"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongo"
4
+
5
+ gem "rails", "4.1"
6
+ gem "devise", Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1") ? "3.5.10" : ">= 4.2"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid"
4
+
5
+ gem "rails", "4.1"
6
+ gem "devise", Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1") ? "3.5.10" : ">= 4.2"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongo"
4
+
5
+ gem "rails", "4.2"
6
+ gem "devise", Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1") ? "3.5.10" : ">= 4.2"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid"
4
+
5
+ gem "rails", "4.2"
6
+ gem "devise", Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1") ? "3.5.10" : ">= 4.2"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path => "../"
@@ -0,0 +1 @@
1
+ require "mongo_session_store"
@@ -0,0 +1,27 @@
1
+ module MongoSessionStore
2
+ def self.collection_name
3
+ @collection_name
4
+ end
5
+
6
+ def self.collection_name=(name)
7
+ @collection_name = name
8
+
9
+ if defined?(MongoStore::Session)
10
+ MongoStore::Session.reset_collection
11
+ elsif defined?(MongoidStore::Session)
12
+ MongoidStore::Session.store_in \
13
+ :collection => MongoSessionStore.collection_name
14
+ end
15
+
16
+ @collection_name
17
+ end
18
+
19
+ # default collection name for all the stores
20
+ self.collection_name = "sessions"
21
+ end
22
+
23
+ if defined?(Mongoid)
24
+ require "mongo_session_store/mongoid_store"
25
+ elsif defined?(Mongo)
26
+ require "mongo_session_store/mongo_store"
27
+ end
@@ -0,0 +1,102 @@
1
+ require "mongo_session_store/mongo_store_base"
2
+
3
+ module ActionDispatch
4
+ module Session
5
+ class MongoStore < MongoStoreBase
6
+ class Session
7
+ class << self
8
+ attr_writer :database
9
+
10
+ def load(options = {})
11
+ options[:data] = options["data"] if options["data"]
12
+ options[:data] =
13
+ if options[:data]
14
+ unpack(options[:data])
15
+ else
16
+ {}
17
+ end
18
+ new(options)
19
+ end
20
+
21
+ def where(query = {})
22
+ collection.find(query).map { |doc| load(doc) }
23
+ end
24
+
25
+ def database
26
+ return @database if @database
27
+
28
+ raise NoMongoClientError, "MongoStore needs a database, e.g. "\
29
+ "MongoStore::Session.database = Mongo::Client.new("\
30
+ "[\"127.0.0.1:27017\"], database: \"my_app_development\")"
31
+ end
32
+
33
+ def collection
34
+ @collection ||= database[MongoSessionStore.collection_name]
35
+ end
36
+
37
+ def reset_collection
38
+ @collection = nil
39
+ end
40
+
41
+ private
42
+
43
+ def unpack(packed)
44
+ return unless packed
45
+ data = packed.respond_to?(:data) ? packed.data : packed.to_s
46
+ Marshal.load(StringIO.new(data))
47
+ end
48
+ end
49
+
50
+ class NoMongoClientError < StandardError; end
51
+
52
+ attr_accessor :_id, :data, :created_at, :updated_at
53
+
54
+ def initialize(options = {})
55
+ @_id = options[:_id]
56
+ @data = options[:data]
57
+ @created_at = options[:created_at]
58
+ @updated_at = options[:updated_at]
59
+ end
60
+
61
+ def save
62
+ @created_at ||= Time.now.utc
63
+ @updated_at = Time.now.utc
64
+
65
+ scope.replace_one(attributes_for_save, :upsert => true)
66
+ end
67
+
68
+ def destroy
69
+ scope.delete_one
70
+ end
71
+
72
+ private
73
+
74
+ def collection
75
+ self.class.collection
76
+ end
77
+
78
+ def attributes_for_save
79
+ {
80
+ :data => pack(data),
81
+ :created_at => created_at,
82
+ :updated_at => updated_at
83
+ }
84
+ end
85
+
86
+ def scope
87
+ collection.find(:_id => _id)
88
+ end
89
+
90
+ def pack(data)
91
+ BSON::Binary.new(Marshal.dump(data || {}), :generic)
92
+ end
93
+
94
+ def unpack(packed)
95
+ self.class.unpack(packed)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ MongoStore = ActionDispatch::Session::MongoStore