mongoid_sessions 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "mongoid"
4
+ gem "bson_ext"
5
+ gem "activesupport"
6
+
7
+ group :development do
8
+ gem "bundler"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (2.3.5)
5
+ bson (1.9.1)
6
+ bson_ext (1.9.1)
7
+ bson (~> 1.9.1)
8
+ durran-validatable (2.0.1)
9
+ mongo (1.9.1)
10
+ bson (~> 1.9.1)
11
+ mongoid (1.2.14)
12
+ activesupport (<= 2.3.5)
13
+ durran-validatable (>= 2.0.1)
14
+ mongo (>= 0.19.1)
15
+ will_paginate (< 2.9)
16
+ will_paginate (2.3.16)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ activesupport
23
+ bson_ext
24
+ bundler
25
+ mongoid
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Bantik
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.md ADDED
@@ -0,0 +1,4 @@
1
+ mongoid_session_store
2
+ =====================
3
+
4
+ Mongoid port of ActiveRecord session store. Experimental, do not use in production.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,64 @@
1
+ require 'action_dispatch/middleware/session/abstract_store'
2
+
3
+ module ActionDispatch
4
+ module Session
5
+
6
+ class MongoidSessionStore < ActionDispatch::Session::AbstractStore
7
+
8
+ SESSION_RECORD_KEY = 'rack.session.record'
9
+ ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY
10
+
11
+ private
12
+
13
+ def session_class
14
+ Mongoid::SessionStore::Session
15
+ end
16
+
17
+ def get_session(env, sid)
18
+ unless sid and session = session_class.find_by_session_id(sid)
19
+ sid = generate_sid
20
+ session = session_class.new(:session_id => sid, :data => {})
21
+ end
22
+ env[SESSION_RECORD_KEY] = session
23
+ [sid, session.data]
24
+ end
25
+
26
+ def set_session(env, sid, session_data, options)
27
+ record = get_session_model(env, sid)
28
+ record.data = session_data
29
+ return false unless record.save
30
+
31
+ session_data = record.data
32
+ if session_data && session_data.respond_to?(:each_value)
33
+ session_data.each_value do |obj|
34
+ obj.clear_association_cache if obj.respond_to?(:clear_association_cache)
35
+ end
36
+ end
37
+
38
+ sid
39
+ end
40
+
41
+ def destroy_session(env, session_id, options)
42
+ if sid = current_session_id(env)
43
+ get_session_model(env, sid).destroy
44
+ env[SESSION_RECORD_KEY] = nil
45
+ end
46
+
47
+ generate_sid unless options[:drop]
48
+ end
49
+
50
+ def get_session_model(env, sid)
51
+ if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
52
+ env[SESSION_RECORD_KEY] = find_session(sid)
53
+ else
54
+ env[SESSION_RECORD_KEY] ||= find_session(sid)
55
+ end
56
+ end
57
+
58
+ def find_session(id)
59
+ session_class.find_by_session_id(id) ||
60
+ session_class.new(:session_id => id, :data => {})
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ require 'action_dispatch/session/mongoid_session_store'
2
+ require 'mongoid/session_store/session'
3
+
@@ -0,0 +1,34 @@
1
+ module Mongoid
2
+
3
+ module SessionStore
4
+
5
+ class Session
6
+
7
+ include Mongoid::Document
8
+ include Mongoid::Timestamps
9
+
10
+ field :session_id
11
+ field :raw_data
12
+
13
+ def self.find_by_session_id(session_id)
14
+ where(:session_id => session_id).last
15
+ end
16
+
17
+ def data
18
+ self.raw_data.present? && Marshal.load(ActiveSupport::Base64.decode64(self.raw_data)) || {}
19
+ end
20
+
21
+ def data=(raw)
22
+ raw ||= {}
23
+ self.raw_data = ActiveSupport::Base64.encode64(Marshal.dump(raw))
24
+ end
25
+
26
+ def loaded?
27
+ self.raw_data.present?
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -0,0 +1,2 @@
1
+ require 'mongoid/session_store/session'
2
+ require 'action_dispatch/session/mongoid_session_store'
@@ -0,0 +1,3 @@
1
+ module MongoidSessions
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongoid_sessions/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongoid_sessions"
8
+ spec.version = MongoidSessions::VERSION
9
+ spec.authors = ["Bantik"]
10
+ spec.email = ["corey@idolhands.com"]
11
+ spec.description = %q{Mongoid alternative to ActiveRecord::SessionStore.}
12
+ spec.summary = %q{Mongoid alternative to ActiveRecord::SessionStore}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "mongo"
22
+ spec.add_dependency "mongoid"
23
+ spec.add_dependency "bson_ext"
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_sessions
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bantik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongo
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongoid
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bson_ext
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Mongoid alternative to ActiveRecord::SessionStore.
95
+ email:
96
+ - corey@idolhands.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - VERSION
108
+ - lib/action_dispatch/session/mongoid_session_store.rb
109
+ - lib/mongoid/session_store.rb
110
+ - lib/mongoid/session_store/session.rb
111
+ - lib/mongoid_sessions.rb
112
+ - lib/mongoid_sessions/version.rb
113
+ - mongoid_sessions.gemspec
114
+ homepage: ''
115
+ licenses:
116
+ - MIT
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.24
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Mongoid alternative to ActiveRecord::SessionStore
139
+ test_files: []