mongo-rack-session 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ gem 'ruby-debug'
14
+ end
15
+
16
+ gem 'rack'
17
+ gem 'mongo_mapper'
18
+ gem 'i18n'
19
+ gem 'bson_ext', '1.1.5'
20
+ gem "uuid", :git => "git://github.com/assaf/uuid.git"
21
+
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ GIT
2
+ remote: git://github.com/assaf/uuid.git
3
+ revision: 053e94be93bc540737f745ed92504df104a3b9f1
4
+ specs:
5
+ uuid (2.3.1)
6
+ macaddr (~> 1.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.0.3)
12
+ bson (1.1.5)
13
+ bson_ext (1.1.5)
14
+ columnize (0.3.2)
15
+ git (1.2.5)
16
+ i18n (0.5.0)
17
+ jeweler (1.5.2)
18
+ bundler (~> 1.0.0)
19
+ git (>= 1.2.5)
20
+ rake
21
+ jnunemaker-validatable (1.8.4)
22
+ activesupport (>= 2.3.4)
23
+ linecache (0.43)
24
+ macaddr (1.0.0)
25
+ mongo (1.1.5)
26
+ bson (>= 1.1.5)
27
+ mongo_mapper (0.8.6)
28
+ activesupport (>= 2.3.4)
29
+ jnunemaker-validatable (~> 1.8.4)
30
+ plucky (~> 0.3.6)
31
+ plucky (0.3.6)
32
+ mongo (~> 1.1)
33
+ rack (1.2.1)
34
+ rake (0.8.7)
35
+ rcov (0.9.9)
36
+ ruby-debug (0.10.4)
37
+ columnize (>= 0.1)
38
+ ruby-debug-base (~> 0.10.4.0)
39
+ ruby-debug-base (0.10.4)
40
+ linecache (>= 0.3)
41
+ shoulda (2.11.3)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ bson_ext (= 1.1.5)
48
+ bundler (~> 1.0.0)
49
+ i18n
50
+ jeweler (~> 1.5.2)
51
+ mongo_mapper
52
+ rack
53
+ rcov
54
+ ruby-debug
55
+ shoulda
56
+ uuid!
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 David Yang
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,19 @@
1
+ = mongo-rack-session
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to mongo-rack-session
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 David Yang. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "mongo-rack-session"
16
+ gem.version = '0.0.1'
17
+ gem.homepage = "http://github.com/davidyang/mongo-rack-session"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{ one-line summary of your gem}
20
+ gem.description = %Q{longer description of your gem}
21
+ gem.email = "david.g.yang@gmail.com"
22
+ gem.authors = ["David Yang"]
23
+
24
+ gem.add_runtime_dependency 'mongo_mapper'
25
+ gem.add_runtime_dependency 'uuid'
26
+ gem.add_runtime_dependency 'rack'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ task :default => :test
38
+
@@ -0,0 +1,65 @@
1
+ require 'rack/session/abstract/id'
2
+ require 'mongo_mapper'
3
+ require 'uuid'
4
+ require 'active_support' # probably already included from mongo_mapper
5
+
6
+ module Rack
7
+ module Session
8
+ class Mongo < Abstract::ID
9
+ VERSION = '0.1.1'
10
+ class Session
11
+ include MongoMapper::Document
12
+ key "Id", String
13
+ key :Expired, Boolean
14
+ key :StartTimestamp, Time
15
+ key :Timeout, Integer
16
+
17
+ def is_valid?
18
+ if self.Timeout && self.StartTimestamp
19
+ (self.StartTimestamp + (self.Timeout/1000).seconds > Time.now) ? self : nil
20
+ else
21
+ nil
22
+ end
23
+ end
24
+ end
25
+
26
+ DEFAULT_OPTIONS = Abstract::ID::DEFAULT_OPTIONS.merge \
27
+ :mongo_db_name => 'shiro',
28
+ :mongo_collection_name => 'Sessions',
29
+ :mongo_server => '10.0.0.82',
30
+ :default_key => 'JSESSIONID', # cookie key
31
+ :session_class_key => 'Id'
32
+
33
+ def initialize(app, options={})
34
+ super
35
+ @key = options[:key] || @default_options[:default_key]
36
+
37
+ # set up the Session Class either defined by the User or using the one defined above
38
+ @@session_class = options[:session_class] || Session
39
+ @@session_class.set_database_name(options[:mongo_db_name] || @default_options[:mongo_db_name])
40
+ @@session_class.set_collection_name(options[:mongo_collection_name] || @default_options[:mongo_collection_name])
41
+ @@session_class.connection(::Mongo::Connection.new(options[:mongo_server] || @default_options[:mongo_server]))
42
+ @@session_class_key = options[:session_class_key] || @default_options[:session_class_key]
43
+ end
44
+
45
+ def get_session(env, sid)
46
+ sid ||= generate_sid
47
+ session = find_session(sid)
48
+ [sid, session]
49
+ end
50
+
51
+ def set_session(env, session_id, new_session, options)
52
+ new_session.save ? new_session.Id : nil
53
+ end
54
+
55
+ def find_session(sid)
56
+ mongo_session = @@session_class.first(:conditions => {@@session_class_key => sid})
57
+ (mongo_session && mongo_session.is_valid?) || @@session_class.create(@@session_class_key => sid)
58
+ end
59
+
60
+ def generate_sid
61
+ UUID.generate
62
+ end
63
+ end
64
+ end
65
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'mongo-rack-session'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestMongoRackSession < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,264 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo-rack-session
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - David Yang
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-29 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rack
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: mongo_mapper
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: i18n
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: bson_ext
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - "="
70
+ - !ruby/object:Gem::Version
71
+ hash: 25
72
+ segments:
73
+ - 1
74
+ - 1
75
+ - 5
76
+ version: 1.1.5
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: uuid
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ type: :runtime
92
+ version_requirements: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: shoulda
95
+ prerelease: false
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ type: :development
106
+ version_requirements: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: bundler
109
+ prerelease: false
110
+ requirement: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ hash: 23
116
+ segments:
117
+ - 1
118
+ - 0
119
+ - 0
120
+ version: 1.0.0
121
+ type: :development
122
+ version_requirements: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: jeweler
125
+ prerelease: false
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ hash: 7
132
+ segments:
133
+ - 1
134
+ - 5
135
+ - 2
136
+ version: 1.5.2
137
+ type: :development
138
+ version_requirements: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ name: rcov
141
+ prerelease: false
142
+ requirement: &id009 !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ type: :development
152
+ version_requirements: *id009
153
+ - !ruby/object:Gem::Dependency
154
+ name: ruby-debug
155
+ prerelease: false
156
+ requirement: &id010 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ type: :development
166
+ version_requirements: *id010
167
+ - !ruby/object:Gem::Dependency
168
+ name: mongo_mapper
169
+ prerelease: false
170
+ requirement: &id011 !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ hash: 3
176
+ segments:
177
+ - 0
178
+ version: "0"
179
+ type: :runtime
180
+ version_requirements: *id011
181
+ - !ruby/object:Gem::Dependency
182
+ name: uuid
183
+ prerelease: false
184
+ requirement: &id012 !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
+ type: :runtime
194
+ version_requirements: *id012
195
+ - !ruby/object:Gem::Dependency
196
+ name: rack
197
+ prerelease: false
198
+ requirement: &id013 !ruby/object:Gem::Requirement
199
+ none: false
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ hash: 3
204
+ segments:
205
+ - 0
206
+ version: "0"
207
+ type: :runtime
208
+ version_requirements: *id013
209
+ description: longer description of your gem
210
+ email: david.g.yang@gmail.com
211
+ executables: []
212
+
213
+ extensions: []
214
+
215
+ extra_rdoc_files:
216
+ - LICENSE.txt
217
+ - README.rdoc
218
+ files:
219
+ - .document
220
+ - Gemfile
221
+ - Gemfile.lock
222
+ - LICENSE.txt
223
+ - README.rdoc
224
+ - Rakefile
225
+ - lib/mongo-rack-session.rb
226
+ - test/helper.rb
227
+ - test/test_mongo-rack-session.rb
228
+ has_rdoc: true
229
+ homepage: http://github.com/davidyang/mongo-rack-session
230
+ licenses:
231
+ - MIT
232
+ post_install_message:
233
+ rdoc_options: []
234
+
235
+ require_paths:
236
+ - lib
237
+ required_ruby_version: !ruby/object:Gem::Requirement
238
+ none: false
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ hash: 3
243
+ segments:
244
+ - 0
245
+ version: "0"
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ none: false
248
+ requirements:
249
+ - - ">="
250
+ - !ruby/object:Gem::Version
251
+ hash: 3
252
+ segments:
253
+ - 0
254
+ version: "0"
255
+ requirements: []
256
+
257
+ rubyforge_project:
258
+ rubygems_version: 1.3.7
259
+ signing_key:
260
+ specification_version: 3
261
+ summary: one-line summary of your gem
262
+ test_files:
263
+ - test/helper.rb
264
+ - test/test_mongo-rack-session.rb