mongo_session_store-rails3 4.1.0 → 4.1.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cfa82736ec25e1cf342ef21455b2fba8e6a49e2
4
+ data.tar.gz: 5aae0a100f3ba92e18995e9bdc685d8797354a50
5
+ SHA512:
6
+ metadata.gz: 45dd7a838b89375851da0886be0499ba69b9bc4706fc6bd1a335336303c439900266b3a3a688277ca2a443cbebc2cfd8ad7247eb32cf3f462f65b4fafedc827c
7
+ data.tar.gz: 7f06e483bf1db8967507e3c35c79859995b10f63763183c2df4894c08e67adafacc371ecfd07da52fd0d64c80e4c6ec348987b88832649430e06dbeadc790db8
data/.gitignore CHANGED
@@ -5,4 +5,6 @@
5
5
  Gemfile.lock
6
6
  Gemfile_Rails_*.lock
7
7
  *.gem
8
- .rvmrc
8
+ .rvmrc
9
+ *.swo
10
+ *.swp
@@ -3,6 +3,7 @@ script: "rake"
3
3
  rvm:
4
4
  - 1.8.7
5
5
  - 1.9.3
6
+ - 2.0.0
6
7
  - ruby-head
7
8
  - rbx-19mode
8
9
  - jruby-19mode
data/Gemfile CHANGED
@@ -22,10 +22,12 @@ group :development, :test do
22
22
  end
23
23
 
24
24
  if !ENV['MONGO_SESSION_STORE_ORM'] || ENV['MONGO_SESSION_STORE_ORM'] == 'mongoid'
25
- gem 'mongoid', '~> 3.0', :platforms => [:ruby_19, :jruby]
25
+ gem 'mongoid', '~> 3.0', :platforms => [:ruby_19, :jruby, :ruby_20]
26
26
  end
27
27
 
28
- gem 'mongo', MONGO_VERS
28
+ if !ENV['MONGO_SESSION_STORE_ORM'] || ENV['MONGO_SESSION_STORE_ORM'] == 'mongo'
29
+ gem 'mongo', MONGO_VERS
30
+ end
29
31
  gem 'bson_ext', MONGO_VERS, :platforms => :ruby
30
32
 
31
33
  gem 'system_timer', :platforms => :ruby_18
@@ -46,4 +48,4 @@ group :development, :test do
46
48
 
47
49
  gem 'rspec-rails', '2.12.0'
48
50
  gem 'devise'
49
- end
51
+ end
data/README.md CHANGED
@@ -4,7 +4,7 @@
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.8.7, 1.9.3, and JRuby. As of this writing, it also works on Rubinius in 1.9 mode and on Ruby 2.0.0.
7
+ MongoSessionStore is tested [on Travis CI](https://travis-ci.org/brianhempel/mongo_session_store) against Ruby 1.8.7, 1.9.3, 2.0.0, and JRuby. As of this writing, it also works on Rubinius in 1.9.
8
8
 
9
9
  If this gem doesn't work for you, you might next try [mongo_sessions](https://github.com/biilmann/mongo_sessions).
10
10
 
@@ -32,6 +32,19 @@ module MongoSessionStore
32
32
  self.collection_name = "sessions"
33
33
  end
34
34
 
35
- require 'mongo_session_store/mongo_mapper_store'
36
- require 'mongo_session_store/mongoid_store'
37
- require 'mongo_session_store/mongo_store'
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,26 +1,22 @@
1
- begin
2
- require 'mongo_mapper'
3
- require 'mongo_session_store/mongo_store_base'
1
+ require 'mongo_mapper'
2
+ require 'mongo_session_store/mongo_store_base'
4
3
 
5
- module ActionDispatch
6
- module Session
7
- class MongoMapperStore < MongoStoreBase
4
+ module ActionDispatch
5
+ module Session
6
+ class MongoMapperStore < MongoStoreBase
8
7
 
9
- class Session
10
- include MongoMapper::Document
11
- set_collection_name MongoSessionStore.collection_name
8
+ class Session
9
+ include MongoMapper::Document
10
+ set_collection_name MongoSessionStore.collection_name
12
11
 
13
- key :_id, String
14
- key :data, Binary, :default => Marshal.dump({})
15
-
16
- timestamps!
17
- end
12
+ key :_id, String
13
+ key :data, Binary, :default => Marshal.dump({})
18
14
 
15
+ timestamps!
19
16
  end
17
+
20
18
  end
21
19
  end
20
+ end
22
21
 
23
- MongoMapperStore = ActionDispatch::Session::MongoMapperStore
24
-
25
- rescue LoadError
26
- end
22
+ MongoMapperStore = ActionDispatch::Session::MongoMapperStore
@@ -6,23 +6,23 @@ module ActionDispatch
6
6
  class MongoStore < MongoStoreBase
7
7
  class Session
8
8
  attr_accessor :_id, :data, :created_at, :updated_at
9
-
9
+
10
10
  def initialize(options = {})
11
11
  @_id = options[:_id]
12
12
  @data = options[:data] || BSON::Binary.new(Marshal.dump({}))
13
13
  @created_at = options[:created_at]
14
14
  @updated_at = options[:updated_at]
15
15
  end
16
-
16
+
17
17
  def self.load(options = {})
18
18
  options[:data] = options["data"] if options["data"]
19
19
  new(options)
20
20
  end
21
-
21
+
22
22
  def destroy
23
23
  collection.remove :_id => _id
24
24
  end
25
-
25
+
26
26
  def save
27
27
  @created_at ||= Time.now
28
28
  @updated_at = Time.now
@@ -34,19 +34,19 @@ module ActionDispatch
34
34
  :updated_at => @updated_at
35
35
  )
36
36
  end
37
-
37
+
38
38
  def data=(stuff)
39
39
  @data = stuff.to_s
40
40
  end
41
-
41
+
42
42
  def self.where(query = {})
43
43
  collection.find(query).map { |doc| load(doc) }
44
44
  end
45
-
45
+
46
46
  def self.last
47
47
  where.last
48
48
  end
49
-
49
+
50
50
  def self.database
51
51
  if @database
52
52
  @database
@@ -58,19 +58,19 @@ module ActionDispatch
58
58
  raise "MongoStore needs a database, e.g. MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')"
59
59
  end
60
60
  end
61
-
61
+
62
62
  def self.database=(database)
63
63
  @database = database
64
64
  end
65
-
65
+
66
66
  def self.collection
67
67
  @collection ||= database[MongoSessionStore.collection_name]
68
68
  end
69
-
69
+
70
70
  def self.reset_collection
71
71
  @collection = nil
72
72
  end
73
-
73
+
74
74
  def collection
75
75
  self.class.collection
76
76
  end
@@ -12,12 +12,12 @@ module ActionDispatch
12
12
  def self.session_class
13
13
  self::Session
14
14
  end
15
-
15
+
16
16
  private
17
17
  def session_class
18
18
  self.class.session_class
19
19
  end
20
-
20
+
21
21
  def generate_sid
22
22
  # 20 random bytes in url-safe base64
23
23
  SecureRandom.base64(20).gsub('=','').gsub('+','-').gsub('/','_')
@@ -38,7 +38,7 @@ module ActionDispatch
38
38
  # However, ActionPack seems to want a session id instead.
39
39
  record.save ? sid : false
40
40
  end
41
-
41
+
42
42
  def find_session(id)
43
43
  session_class.where(:_id => id).first || session_class.new(:_id => id)
44
44
  end
@@ -55,7 +55,7 @@ module ActionDispatch
55
55
  destroy(env)
56
56
  generate_sid unless options[:drop]
57
57
  end
58
-
58
+
59
59
  def destroy(env)
60
60
  if sid = current_session_id(env)
61
61
  get_session_model(env, sid).destroy
@@ -1,33 +1,29 @@
1
- begin
2
- require 'mongoid'
3
- require 'mongo_session_store/mongo_store_base'
1
+ require 'mongoid'
2
+ require 'mongo_session_store/mongo_store_base'
4
3
 
5
- module ActionDispatch
6
- module Session
7
- class MongoidStore < MongoStoreBase
4
+ module ActionDispatch
5
+ module Session
6
+ class MongoidStore < MongoStoreBase
8
7
 
9
- class Session
10
- include Mongoid::Document
11
- include Mongoid::Timestamps
8
+ class Session
9
+ include Mongoid::Document
10
+ include Mongoid::Timestamps
12
11
 
13
- store_in :collection => MongoSessionStore.collection_name
12
+ store_in :collection => MongoSessionStore.collection_name
14
13
 
15
- field :_id, :type => String
14
+ field :_id, :type => String
16
15
 
17
- field :data, :type => Moped::BSON::Binary, :default => Moped::BSON::Binary.new(:generic, Marshal.dump({}))
16
+ field :data, :type => Moped::BSON::Binary, :default => Moped::BSON::Binary.new(:generic, Marshal.dump({}))
18
17
 
19
- attr_accessible :_id, :data
20
- end
18
+ attr_accessible :_id, :data
19
+ end
21
20
 
22
- private
23
- def pack(data)
24
- Moped::BSON::Binary.new(:generic, Marshal.dump(data))
25
- end
21
+ private
22
+ def pack(data)
23
+ Moped::BSON::Binary.new(:generic, Marshal.dump(data))
26
24
  end
27
25
  end
28
26
  end
29
-
30
- MongoidStore = ActionDispatch::Session::MongoidStore
31
-
32
- rescue LoadError
33
27
  end
28
+
29
+ MongoidStore = ActionDispatch::Session::MongoidStore
@@ -1,3 +1,3 @@
1
1
  module MongoSessionStore
2
- VERSION = "4.1.0"
2
+ VERSION = "4.1.1"
3
3
  end
@@ -74,16 +74,16 @@ describe Devise::SessionsController do
74
74
 
75
75
  it "stores the session in the sessions collection" do
76
76
  collection = db["sessions"]
77
- collection.count.should == 0
77
+ collection.find.count.should == 0
78
78
  create_user
79
- collection.count.should == 1
79
+ collection.find.count.should == 1
80
80
  end
81
81
 
82
82
  it "allows renaming of the collection that stores the sessions" do
83
83
  collection = db["dance_parties"]
84
- collection.count.should == 0
84
+ collection.find.count.should == 0
85
85
  MongoSessionStore.collection_name = "dance_parties"
86
86
  create_user
87
- collection.count.should == 1
87
+ collection.find.count.should == 1
88
88
  end
89
- end
89
+ end
@@ -12,7 +12,13 @@ require "rails_#{rails_version}_app/config/environment"
12
12
  require 'rspec/rails'
13
13
 
14
14
  def db
15
- Mongo::Connection.new[database_name]
15
+ if defined?(Mongoid)
16
+ MongoidStore::Session.mongo_session
17
+ elsif defined?(MongoMapper)
18
+ MongoMapper.database
19
+ elsif defined?(Mongo)
20
+ Mongo::Connection.new[database_name]
21
+ end
16
22
  end
17
23
 
18
24
  def database_name
@@ -31,8 +37,6 @@ RSpec.configure do |config|
31
37
  end
32
38
 
33
39
  config.before :each do
34
- drop_collections_in(MongoidStore::Session.mongo_session) if defined?(Mongoid)
35
- drop_collections_in(MongoMapper.database) if defined?(MongoMapper)
36
40
  drop_collections_in(db)
37
41
  User.delete_all
38
42
  end
metadata CHANGED
@@ -1,50 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongo_session_store-rails3
3
- version: !ruby/object:Gem::Version
4
- hash: 59
5
- prerelease:
6
- segments:
7
- - 4
8
- - 1
9
- - 0
10
- version: 4.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.1.1
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Brian Hempel
14
- - "Nicolas M\xC3\xA9rouze"
8
+ - Nicolas Mérouze
15
9
  - Tony Pitale
16
10
  - Chris Brickley
17
11
  autorequire:
18
12
  bindir: bin
19
13
  cert_chain: []
20
-
21
- date: 2013-06-10 00:00:00 Z
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
14
+ date: 2013-06-10 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
24
17
  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
- - 3
34
- - 1
35
- version: "3.1"
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '3.1'
36
23
  type: :runtime
37
- version_requirements: *id001
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
38
30
  description:
39
- email:
31
+ email:
40
32
  - plasticchicken@gmail.com
41
33
  executables: []
42
-
43
34
  extensions: []
44
-
45
35
  extra_rdoc_files: []
46
-
47
- files:
36
+ files:
48
37
  - .gitignore
49
38
  - .rspec
50
39
  - .travis.yml
@@ -175,38 +164,29 @@ files:
175
164
  - spec/spec_helper.rb
176
165
  homepage: http://github.com/brianhempel/mongo_session_store
177
166
  licenses: []
178
-
167
+ metadata: {}
179
168
  post_install_message:
180
169
  rdoc_options: []
181
-
182
- require_paths:
170
+ require_paths:
183
171
  - lib
184
- required_ruby_version: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
191
- - 0
192
- version: "0"
193
- required_rubygems_version: !ruby/object:Gem::Requirement
194
- none: false
195
- requirements:
196
- - - ">="
197
- - !ruby/object:Gem::Version
198
- hash: 3
199
- segments:
200
- - 0
201
- version: "0"
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
202
182
  requirements: []
203
-
204
183
  rubyforge_project:
205
- rubygems_version: 1.8.24
184
+ rubygems_version: 2.0.3
206
185
  signing_key:
207
- specification_version: 3
208
- summary: Rails session stores for MongoMapper, Mongoid, or any other ODM. Rails 3.1 and 3.2 compatible.
209
- test_files:
186
+ specification_version: 4
187
+ summary: Rails session stores for MongoMapper, Mongoid, or any other ODM. Rails 3.1
188
+ and 3.2 compatible.
189
+ test_files:
210
190
  - perf/benchmark.rb
211
191
  - spec/integration_with_devise_spec.rb
212
192
  - spec/rails_3.1_app/.gitignore