mongoid_session_store_ap 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1ab3415905c05afaf3c34f7b00f948bccb52918
4
+ data.tar.gz: ed2f59b0155098100b8dff57ad3d34adc6fea178
5
+ SHA512:
6
+ metadata.gz: f421c30a76a1a33112565d03294d1f222c7505d16d35dc0135c02e02b8852c2101f229ccb0d907778c0bec485eef61b09e77b30d78b574260e0bd7135d7811a0
7
+ data.tar.gz: d1e901fe4d0666ce2341a7bf608dc6b20672a7e1931348ecb811649be736f85812b71a1be569c48dfb790fe02794d6f959695bd72d00df39ef9324c744745498
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ = mongoid_session_store
2
+
3
+ store rails 3 sessions in mongoDB using mongoid.
4
+
5
+ == Installation
6
+ This gem supports rails 3, rails 3.1 and mongoid 2.0
7
+
8
+ gem install mongoid_session_store
9
+
10
+ == Setup
11
+
12
+ In your Gemfile:
13
+
14
+ gem "mongoid", "~> 2.0"
15
+ gem "bson_ext", "~> 1.3"
16
+ gem "mongoid_session_store"
17
+
18
+ In the session_store initializer (config/initializers/session_store.rb) you can comment out every line as
19
+ mongoid session store will be setup for use when added to the gemfile.
20
+
21
+ If you want to be more explicit you can comment the currently setup store and add:
22
+
23
+ Example::Application.config.session_store :mongoid_store
24
+
25
+ == Rake Tasks
26
+ Mongoid Session Store comes with a rake task to clear out the sessions it stores in mongoDB
27
+
28
+ rake db:mongoid:sessions:clear
29
+
30
+ == Note on Patches/Pull Requests
31
+
32
+ * Fork the project.
33
+ * Make your feature addition or bug fix.
34
+ * Add tests for it. This is important so I don't break it in a
35
+ future version unintentionally.
36
+ * Commit, do not mess with rakefile, version, or history.
37
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
38
+ * Send me a pull request. Bonus points for topic branches.
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2010 Ryan Fitzgerald. See MIT-LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ require 'bundler/gem_tasks'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+ begin
9
+ require 'rdoc/task'
10
+ rescue LoadError
11
+ require 'rdoc/rdoc'
12
+ require 'rake/rdoctask'
13
+ RDoc::Task = Rake::RDocTask
14
+ end
15
+
16
+ RDoc::Task.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'MongoidSessionStore'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README.rdoc')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task :default => :test
@@ -0,0 +1,16 @@
1
+ require 'rails'
2
+
3
+ module MongoidSessionStore
4
+
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load "tasks/mongoid_session_store_tasks.rake"
8
+ end
9
+
10
+ initializer "setup mongoid session store" do |app|
11
+ require 'mongoid_session_store/mongoid_store'
12
+ app.config.session_store :mongoid_store
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,94 @@
1
+ module ActionDispatch
2
+ module Session
3
+ class MongoidStore < AbstractStore
4
+
5
+ class Session
6
+ include Mongoid::Document
7
+
8
+ store_in collection: 'sessions'
9
+
10
+ #identity :type => String
11
+ field :id, type: String
12
+ attr_accessible :id
13
+ field :data, :type => String, :default => [Marshal.dump({})].pack("m*")
14
+ field :last_active_time, type: Time, default: Time.now
15
+ end
16
+
17
+ # The class used for session storage.
18
+ cattr_accessor :session_class
19
+ self.session_class = Session
20
+
21
+ SESSION_RECORD_KEY = 'rack.session.record'
22
+ ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY if ::Rails.version >= "3.1"
23
+
24
+ private
25
+
26
+ def get_session(env, sid)
27
+ expire_after = env[ENV_SESSION_OPTIONS_KEY][:expire_after]
28
+ sid ||= generate_sid
29
+ session = find_session(sid)
30
+ seconds_since_last_access = Time.now - session.last_active_time.to_time
31
+ if expire_after and seconds_since_last_access > expire_after
32
+ # clear all the existing data
33
+ session.data = [Marshal.dump({})].pack("m*")
34
+ session.save
35
+ end
36
+
37
+ env[SESSION_RECORD_KEY] = session
38
+ [sid, unpack(session.data)]
39
+ end
40
+
41
+ def set_session(env, sid, session_data, options = nil)
42
+ record = get_session_model(env, sid)
43
+ record.last_active_time = Time.now
44
+ record.data = pack(session_data)
45
+
46
+ # Rack spec dictates that set_session should return true or false
47
+ # depending on whether or not the session was saved or not.
48
+ # However, ActionPack seems to want a session id instead.
49
+ record.save ? sid : false
50
+ end
51
+
52
+ def find_session(id)
53
+ @@session_class.find_or_create_by(:id => id)
54
+ end
55
+
56
+ # def destroy(env)
57
+ # if sid = current_session_id(env)
58
+ # find_session(sid).destroy
59
+ # end
60
+ # end
61
+
62
+ def destroy(env)
63
+ destroy_session(env, current_session_id(env), {})
64
+ end
65
+
66
+ def destroy_session(env, session_id, options)
67
+ if sid = current_session_id(env)
68
+ get_session_model(env, sid).destroy
69
+ env[SESSION_RECORD_KEY] = nil
70
+ end
71
+
72
+ generate_sid unless options[:drop]
73
+ end
74
+
75
+ def get_session_model(env, sid)
76
+ if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
77
+ env[SESSION_RECORD_KEY] = find_session(sid)
78
+ else
79
+ env[SESSION_RECORD_KEY] ||= find_session(sid)
80
+ end
81
+ end
82
+
83
+ def pack(data)
84
+ [Marshal.dump(data)].pack("m*")
85
+ end
86
+
87
+ def unpack(packed)
88
+ return nil unless packed
89
+ Marshal.load(packed.unpack("m*").first)
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,10 @@
1
+ namespace :db do
2
+ namespace :mongoid do
3
+ namespace :sessions do
4
+ desc "Clears sessions stored in mongoDB"
5
+ task :clear => :environment do
6
+ ActionDispatch::Session::MongoidStore::Session.destroy_all
7
+ end
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_session_store_ap
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Fitzgerald, Dimitri Kurashvili
8
+ - Code Brew Studios, C12.ge
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '3.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '3.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: mongoid
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ description: Store rails 3 sessions in mongoDB (with mongoid3 gem).
43
+ email:
44
+ - ryan@codebrewstudios.com, dimitri@c12.ge
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - lib/mongoid_session_store.rb
53
+ - lib/mongoid_session_store/mongoid_store.rb
54
+ - lib/tasks/mongoid_session_store_tasks.rake
55
+ homepage: http://github.com/dimakura/mongoid_session_store
56
+ licenses: []
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.2.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Store rails 3 sessions in mongoDB (with mongoid3 gem).
78
+ test_files: []