mongo_session_store 2.0.0 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rubocop.yml +43 -0
- data/.travis.yml +37 -0
- data/CHANGELOG.md +49 -0
- data/Dangerfile +1 -0
- data/Gemfile +3 -0
- data/LICENSE +23 -0
- data/README.md +106 -43
- data/Rakefile +90 -0
- data/gemfiles/rails-4.0-mongo.gemfile +9 -0
- data/gemfiles/rails-4.0-mongoid.gemfile +9 -0
- data/gemfiles/rails-4.1-mongo.gemfile +9 -0
- data/gemfiles/rails-4.1-mongoid.gemfile +9 -0
- data/gemfiles/rails-4.2-mongo.gemfile +9 -0
- data/gemfiles/rails-4.2-mongoid.gemfile +9 -0
- data/lib/mongo_session_store.rb +27 -1
- data/lib/mongo_session_store/mongo_store.rb +102 -0
- data/lib/mongo_session_store/mongo_store_base.rb +65 -0
- data/lib/mongo_session_store/mongoid_store.rb +52 -0
- data/lib/mongo_session_store/version.rb +3 -0
- data/mongo_session_store.gemspec +25 -0
- data/perf/benchmark.rb +101 -0
- data/spec/.rubocop.yml +4 -0
- data/spec/integrations/devise_spec.rb +109 -0
- data/spec/lib/mongo_session_store/mongo_store/session_spec.rb +247 -0
- data/spec/lib/mongo_session_store/mongo_store_base_spec.rb +269 -0
- data/spec/lib/mongo_session_store/mongo_store_spec.rb +13 -0
- data/spec/lib/mongo_session_store/mongoid_store/session_spec.rb +82 -0
- data/spec/lib/mongo_session_store/mongoid_store_spec.rb +13 -0
- data/spec/lib/mongo_session_store_spec.rb +64 -0
- data/spec/rails_helper.rb +19 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/apps/rails_4.0_app/Rakefile +6 -0
- data/spec/support/apps/rails_4.0_app/app/controllers/application_controller.rb +5 -0
- data/spec/support/apps/rails_4.0_app/app/controllers/home_controller.rb +4 -0
- data/spec/support/apps/rails_4.0_app/app/models/user.rb +5 -0
- data/spec/support/apps/rails_4.0_app/app/views/home/index.html.erb +10 -0
- data/spec/support/apps/rails_4.0_app/app/views/layouts/application.html.erb +17 -0
- data/spec/support/apps/rails_4.0_app/bin/bundle +3 -0
- data/spec/support/apps/rails_4.0_app/bin/rails +4 -0
- data/spec/support/apps/rails_4.0_app/bin/rake +4 -0
- data/spec/support/apps/rails_4.0_app/config.ru +4 -0
- data/spec/support/apps/rails_4.0_app/config/application.rb +11 -0
- data/spec/support/apps/rails_4.0_app/config/boot.rb +4 -0
- data/spec/support/apps/rails_4.0_app/config/database.yml +11 -0
- data/spec/support/apps/rails_4.0_app/config/environment.rb +5 -0
- data/spec/support/apps/rails_4.0_app/config/environments/development.rb +12 -0
- data/spec/support/apps/rails_4.0_app/config/environments/test.rb +19 -0
- data/spec/support/apps/rails_4.0_app/config/initializers/devise.rb +254 -0
- data/spec/support/apps/rails_4.0_app/config/initializers/secret_token.rb +12 -0
- data/spec/support/apps/rails_4.0_app/config/initializers/session_store.rb +1 -0
- data/spec/support/apps/rails_4.0_app/config/locales/devise.en.yml +59 -0
- data/spec/support/apps/rails_4.0_app/config/locales/en.yml +23 -0
- data/spec/support/apps/rails_4.0_app/config/mongo.yml +11 -0
- data/spec/support/apps/rails_4.0_app/config/mongoid.yml +13 -0
- data/spec/support/apps/rails_4.0_app/config/routes.rb +4 -0
- data/spec/support/apps/rails_4.0_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
- data/spec/support/apps/rails_4.0_app/db/schema.rb +25 -0
- data/spec/support/apps/rails_4.0_app/db/seeds.rb +7 -0
- data/spec/support/apps/rails_4.0_app/lib/assets/.keep +0 -0
- data/spec/support/apps/rails_4.0_app/lib/tasks/.keep +0 -0
- data/spec/support/apps/rails_4.0_app/log/.keep +0 -0
- data/spec/support/apps/rails_4.0_app/public/404.html +58 -0
- data/spec/support/apps/rails_4.0_app/public/422.html +58 -0
- data/spec/support/apps/rails_4.0_app/public/500.html +57 -0
- data/spec/support/apps/rails_4.0_app/public/favicon.ico +0 -0
- data/spec/support/apps/rails_4.0_app/public/robots.txt +5 -0
- data/spec/support/apps/rails_4.1_app/Rakefile +3 -0
- data/spec/support/apps/rails_4.1_app/app/controllers/application_controller.rb +5 -0
- data/spec/support/apps/rails_4.1_app/app/controllers/home_controller.rb +4 -0
- data/spec/support/apps/rails_4.1_app/app/models/user.rb +5 -0
- data/spec/support/apps/rails_4.1_app/app/views/home/index.html.erb +10 -0
- data/spec/support/apps/rails_4.1_app/app/views/layouts/application.html.erb +17 -0
- data/spec/support/apps/rails_4.1_app/bin/bundle +3 -0
- data/spec/support/apps/rails_4.1_app/bin/rails +4 -0
- data/spec/support/apps/rails_4.1_app/bin/rake +4 -0
- data/spec/support/apps/rails_4.1_app/config.ru +2 -0
- data/spec/support/apps/rails_4.1_app/config/application.rb +11 -0
- data/spec/support/apps/rails_4.1_app/config/boot.rb +4 -0
- data/spec/support/apps/rails_4.1_app/config/database.yml +11 -0
- data/spec/support/apps/rails_4.1_app/config/environment.rb +5 -0
- data/spec/support/apps/rails_4.1_app/config/environments/development.rb +12 -0
- data/spec/support/apps/rails_4.1_app/config/environments/test.rb +19 -0
- data/spec/support/apps/rails_4.1_app/config/initializers/devise.rb +254 -0
- data/spec/support/apps/rails_4.1_app/config/initializers/session_store.rb +1 -0
- data/spec/support/apps/rails_4.1_app/config/locales/devise.en.yml +59 -0
- data/spec/support/apps/rails_4.1_app/config/locales/en.yml +23 -0
- data/spec/support/apps/rails_4.1_app/config/mongo.yml +11 -0
- data/spec/support/apps/rails_4.1_app/config/mongoid.yml +13 -0
- data/spec/support/apps/rails_4.1_app/config/routes.rb +4 -0
- data/spec/support/apps/rails_4.1_app/config/secrets.yml +22 -0
- data/spec/support/apps/rails_4.1_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
- data/spec/support/apps/rails_4.1_app/db/schema.rb +25 -0
- data/spec/support/apps/rails_4.1_app/db/seeds.rb +7 -0
- data/spec/support/apps/rails_4.1_app/lib/assets/.keep +0 -0
- data/spec/support/apps/rails_4.1_app/lib/tasks/.keep +0 -0
- data/spec/support/apps/rails_4.1_app/log/.keep +0 -0
- data/spec/support/apps/rails_4.1_app/public/404.html +67 -0
- data/spec/support/apps/rails_4.1_app/public/422.html +67 -0
- data/spec/support/apps/rails_4.1_app/public/500.html +66 -0
- data/spec/support/apps/rails_4.1_app/public/favicon.ico +0 -0
- data/spec/support/apps/rails_4.1_app/public/robots.txt +5 -0
- data/spec/support/apps/rails_4.2_app/Rakefile +2 -0
- data/spec/support/apps/rails_4.2_app/app/controllers/application_controller.rb +5 -0
- data/spec/support/apps/rails_4.2_app/app/controllers/home_controller.rb +4 -0
- data/spec/support/apps/rails_4.2_app/app/models/user.rb +5 -0
- data/spec/support/apps/rails_4.2_app/app/views/home/index.html.erb +10 -0
- data/spec/support/apps/rails_4.2_app/app/views/layouts/application.html.erb +15 -0
- data/spec/support/apps/rails_4.2_app/bin/bundle +3 -0
- data/spec/support/apps/rails_4.2_app/bin/rails +8 -0
- data/spec/support/apps/rails_4.2_app/bin/rake +4 -0
- data/spec/support/apps/rails_4.2_app/config.ru +4 -0
- data/spec/support/apps/rails_4.2_app/config/application.rb +11 -0
- data/spec/support/apps/rails_4.2_app/config/boot.rb +3 -0
- data/spec/support/apps/rails_4.2_app/config/database.yml +11 -0
- data/spec/support/apps/rails_4.2_app/config/environment.rb +5 -0
- data/spec/support/apps/rails_4.2_app/config/environments/development.rb +12 -0
- data/spec/support/apps/rails_4.2_app/config/environments/test.rb +19 -0
- data/spec/support/apps/rails_4.2_app/config/initializers/devise.rb +254 -0
- data/spec/support/apps/rails_4.2_app/config/initializers/session_store.rb +1 -0
- data/spec/support/apps/rails_4.2_app/config/locales/en.yml +23 -0
- data/spec/support/apps/rails_4.2_app/config/mongo.yml +11 -0
- data/spec/support/apps/rails_4.2_app/config/mongoid.yml +13 -0
- data/spec/support/apps/rails_4.2_app/config/routes.rb +4 -0
- data/spec/support/apps/rails_4.2_app/config/secrets.yml +22 -0
- data/spec/support/apps/rails_4.2_app/db/migrate/20140301171212_add_devise_users.rb +11 -0
- data/spec/support/apps/rails_4.2_app/db/schema.rb +25 -0
- data/spec/support/apps/rails_4.2_app/db/seeds.rb +7 -0
- data/spec/support/helpers/session_id_helper.rb +5 -0
- data/spec/support/helpers/test_database_helper.rb +22 -0
- metadata +360 -92
- data/lib/mongo_session_store/mongo_mapper.rb +0 -60
- data/lib/mongo_session_store/mongoid.rb +0 -59
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'mongo_mapper'
|
2
|
-
|
3
|
-
module ActionDispatch
|
4
|
-
module Session
|
5
|
-
class MongoMapperStore < AbstractStore
|
6
|
-
|
7
|
-
class Session
|
8
|
-
include MongoMapper::Document
|
9
|
-
key :data, String, :default => [Marshal.dump({})].pack("m*")
|
10
|
-
timestamps!
|
11
|
-
|
12
|
-
ensure_index :updated_at if MongoMapper.class_variables.include? '@@database'
|
13
|
-
end
|
14
|
-
|
15
|
-
# The class used for session storage.
|
16
|
-
cattr_accessor :session_class
|
17
|
-
self.session_class = Session
|
18
|
-
|
19
|
-
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
20
|
-
|
21
|
-
private
|
22
|
-
def generate_sid
|
23
|
-
BSON::ObjectId.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def get_session(env, sid)
|
27
|
-
sid ||= generate_sid
|
28
|
-
session = find_session(sid)
|
29
|
-
env[SESSION_RECORD_KEY] = session
|
30
|
-
[sid, unpack(session.data)]
|
31
|
-
end
|
32
|
-
|
33
|
-
def set_session(env, sid, session_data)
|
34
|
-
record = env[SESSION_RECORD_KEY] ||= find_session(sid)
|
35
|
-
record.data = pack(session_data)
|
36
|
-
# Rack spec dictates that set_session should return true or false
|
37
|
-
# depending on whether or not the session was saved or not.
|
38
|
-
# However, ActionPack seems to want a session id instead.
|
39
|
-
record.save ? sid : false
|
40
|
-
end
|
41
|
-
|
42
|
-
def find_session(id)
|
43
|
-
@@session_class.find(id) ||
|
44
|
-
@@session_class.new(:id=>id)
|
45
|
-
rescue BSON::InvalidObjectId
|
46
|
-
@@session_class.new(:id => generate_sid)
|
47
|
-
end
|
48
|
-
|
49
|
-
def pack(data)
|
50
|
-
[Marshal.dump(data)].pack("m*")
|
51
|
-
end
|
52
|
-
|
53
|
-
def unpack(packed)
|
54
|
-
return nil unless packed
|
55
|
-
Marshal.load(packed.unpack("m*").first)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'mongoid'
|
2
|
-
|
3
|
-
module ActionDispatch
|
4
|
-
module Session
|
5
|
-
class MongoidStore < AbstractStore
|
6
|
-
|
7
|
-
class Session
|
8
|
-
include Mongoid::Document
|
9
|
-
include Mongoid::Timestamps
|
10
|
-
|
11
|
-
field :data, :type => String, :default => [Marshal.dump({})].pack("m*")
|
12
|
-
index :updated_at
|
13
|
-
end
|
14
|
-
|
15
|
-
# The class used for session storage.
|
16
|
-
cattr_accessor :session_class
|
17
|
-
self.session_class = Session
|
18
|
-
|
19
|
-
SESSION_RECORD_KEY = 'rack.session.record'.freeze
|
20
|
-
|
21
|
-
private
|
22
|
-
def generate_sid
|
23
|
-
BSON::ObjectId.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def get_session(env, sid)
|
27
|
-
sid ||= generate_sid
|
28
|
-
session = find_session(sid)
|
29
|
-
env[SESSION_RECORD_KEY] = session
|
30
|
-
[sid, unpack(session.data)]
|
31
|
-
end
|
32
|
-
|
33
|
-
def set_session(env, sid, session_data)
|
34
|
-
record = env[SESSION_RECORD_KEY] ||= find_session(sid)
|
35
|
-
record.data = pack(session_data)
|
36
|
-
# Rack spec dictates that set_session should return true or false
|
37
|
-
# depending on whether or not the session was saved or not.
|
38
|
-
# However, ActionPack seems to want a session id instead.
|
39
|
-
record.save ? sid : false
|
40
|
-
end
|
41
|
-
|
42
|
-
def find_session(id)
|
43
|
-
id = BSON::ObjectId.from_string(id.to_s)
|
44
|
-
@@session_class.first(:conditions => { :_id => id }) ||
|
45
|
-
@@session_class.new(:id => id)
|
46
|
-
end
|
47
|
-
|
48
|
-
def pack(data)
|
49
|
-
[Marshal.dump(data)].pack("m*")
|
50
|
-
end
|
51
|
-
|
52
|
-
def unpack(packed)
|
53
|
-
return nil unless packed
|
54
|
-
Marshal.load(packed.unpack("m*").first)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|