mongo_session_store-rails3 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,37 +10,45 @@ MongoSessionStore is compatible with Rails 3.0 and 3.1
10
10
 
11
11
  In your Gemfile:
12
12
 
13
- gem "mongo_mapper"
14
- gem "mongo_session_store-rails3"
13
+ ```ruby
14
+ gem "mongo_mapper" # or "Mongoid," or another Mongo ODM, or nothing
15
+ gem "mongo_session_store-rails3"
16
+ ```
15
17
 
16
18
  In the session_store initializer (config/initializers/session_store.rb):
17
19
 
18
- # MongoMapper
19
- MyApp::Application.config.session_store = :mongo_mapper_store
20
-
21
- # Mongoid
22
- MyApp::Application.config.session_store = :mongoid_store
23
-
24
- # anything else
25
- MyApp::Application.config.session_store = :mongo_store
26
- ActionDispatch::Session:MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')
20
+ ```ruby
21
+ # MongoMapper
22
+ MyApp::Application.config.session_store = :mongo_mapper_store
23
+
24
+ # Mongoid
25
+ MyApp::Application.config.session_store = :mongoid_store
26
+
27
+ # anything else
28
+ MyApp::Application.config.session_store = :mongo_store
29
+ MongoStore::Session.database = Mongo::Connection.new.db('my_app_development')
30
+ ```
27
31
 
28
32
  Note: If you choose to use the :mongo_store you only need to set its database if you aren't using MongoMapper or Mongoid in your project.
29
33
 
30
34
  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:
31
35
 
32
- MongoSessionStore.collection_name = "client_sessions"
36
+ ```ruby
37
+ MongoSessionStore.collection_name = "client_sessions"
38
+ ```
33
39
 
34
- If for some reason you want to query your sessions:
40
+ And if for some reason you want to query your sessions:
35
41
 
36
- # MongoMapper
37
- ActionDispatch::Session:MongoMapperStore::Session.where(:updated_at.gt => 2.days.ago)
42
+ ```ruby
43
+ # MongoMapper
44
+ MongoMapperStore::Session.where(:updated_at.gt => 2.days.ago)
38
45
 
39
- # Mongoid
40
- ActionDispatch::Session:MongoidStore::Session.where(:updated_at.gt => 2.days.ago)
41
-
42
- # Plain old Mongo
43
- ActionDispatch::Session:MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })
46
+ # Mongoid
47
+ MongoidStore::Session.where(:updated_at.gt => 2.days.ago)
48
+
49
+ # Plain old Mongo
50
+ MongoStore::Session.where('updated_at' => { '$gt' => 2.days.ago })
51
+ ```
44
52
 
45
53
  ## Performance
46
54
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.0.2
@@ -6,16 +6,16 @@ module MongoSessionStore
6
6
  def self.collection_name=(name)
7
7
  @collection_name = name
8
8
 
9
- if defined?(ActionDispatch::Session::MongoStore::Session)
10
- ActionDispatch::Session::MongoStore::Session.reset_collection
9
+ if defined?(MongoStore::Session)
10
+ MongoStore::Session.reset_collection
11
11
  end
12
12
 
13
- if defined?(ActionDispatch::Session::MongoMapperStore::Session)
14
- ActionDispatch::Session::MongoMapperStore::Session.set_collection_name(name)
13
+ if defined?(MongoMapperStore::Session)
14
+ MongoMapperStore::Session.set_collection_name(name)
15
15
  end
16
16
 
17
- if defined?(ActionDispatch::Session::MongoidStore::Session)
18
- ActionDispatch::Session::MongoidStore::Session.store_in(name)
17
+ if defined?(MongoidStore::Session)
18
+ MongoidStore::Session.store_in(name)
19
19
  end
20
20
  end
21
21
 
@@ -5,16 +5,22 @@ begin
5
5
  module ActionDispatch
6
6
  module Session
7
7
  class MongoMapperStore < MongoStoreBase
8
+
8
9
  class Session
9
10
  include MongoMapper::Document
10
11
  set_collection_name MongoSessionStore.collection_name
11
- key :_id, String
12
+
13
+ key :_id, String
12
14
  key :data, Binary, :default => Marshal.dump({})
15
+
13
16
  timestamps!
14
17
  end
18
+
15
19
  end
16
20
  end
17
21
  end
18
22
 
23
+ MongoMapperStore = ActionDispatch::Session::MongoMapperStore
24
+
19
25
  rescue LoadError
20
26
  end
@@ -7,15 +7,15 @@ module ActionDispatch
7
7
  class Session
8
8
  attr_accessor :_id, :data, :created_at, :updated_at
9
9
 
10
- def initialize(options={})
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
- def self.load(options={})
18
- options[:data] = options["data"].to_s if options["data"]
17
+ def self.load(options = {})
18
+ options[:data] = options["data"] if options["data"]
19
19
  new(options)
20
20
  end
21
21
 
@@ -55,7 +55,7 @@ module ActionDispatch
55
55
  elsif defined?(Mongoid)
56
56
  Mongoid.database
57
57
  else
58
- raise "MongoStore needs a database, e.g. #{name.to_s}.database = Mongo::Connection.new.db('my_app_development')"
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
 
@@ -78,3 +78,5 @@ module ActionDispatch
78
78
  end
79
79
  end
80
80
  end
81
+
82
+ MongoStore = ActionDispatch::Session::MongoStore
@@ -20,15 +20,12 @@ begin
20
20
  def pack(data)
21
21
  BSON::Binary.new(Marshal.dump(data))
22
22
  end
23
-
24
- def unpack(packed)
25
- return nil unless packed
26
- Marshal.load(StringIO.new(packed.to_s))
27
- end
28
23
 
29
24
  end
30
25
  end
31
26
  end
27
+
28
+ MongoidStore = ActionDispatch::Session::MongoidStore
32
29
 
33
30
  rescue LoadError
34
31
  end
data/perf/benchmark.rb CHANGED
@@ -5,7 +5,7 @@ require 'bundler/setup'
5
5
  Bundler.require(:development)
6
6
 
7
7
  require 'action_dispatch'
8
- require File.join(File.dirname(__FILE__),'..','lib','mongo_session_store')
8
+ require File.join(File.dirname(__FILE__),'..','lib','mongo_session_store-rails3')
9
9
 
10
10
  MongoMapper.database = "test_session_stores"
11
11
  Mongoid.database = Mongo::Connection.new.db("test_session_stores")
@@ -79,9 +79,9 @@ def benchmark_store(store)
79
79
  puts " Index sizes: #{stats['indexSizes'].inspect}"
80
80
  end
81
81
 
82
- mongo_mapper_store = ActionDispatch::Session::MongoMapperStore.new(nil)
83
- mongoid_store = ActionDispatch::Session::MongoidStore.new(nil)
84
- mongo_store = ActionDispatch::Session::MongoStore.new(nil)
82
+ mongo_mapper_store = MongoMapperStore.new(nil)
83
+ mongoid_store = MongoidStore.new(nil)
84
+ mongo_store = MongoStore.new(nil)
85
85
 
86
86
  puts "MongoMapperStore..."
87
87
  benchmark_store(mongo_mapper_store)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_session_store-rails3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 1
10
- version: 3.0.1
9
+ - 2
10
+ version: 3.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Hempel
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-07-25 00:00:00 -04:00
21
+ date: 2011-07-27 00:00:00 -04:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency