mongo_session_gaggle 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+
2
+ Copyright (c) Zedkit.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
6
+ modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7
+ Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+
2
+ === Mongo Session Gaggle
3
+
4
+ A simple barebones session store for MongoDB, for Rails 3.x only, with no extra code for Rack applications. It also will
5
+ log the runtime for session retrieval and updates. You must connect to MongoDB on its behalf.
6
+
7
+ === Installation
8
+
9
+ gem install mongo_session_gaggle
10
+
11
+ === Configuration
12
+
13
+ At Zedkit we use the Mongoid ORM. An initializer example with a connection from there would be as follows:
14
+
15
+ Rails.application.config.session_store :mongo_store, :key => '_whatever', :expire_after => 30.days,
16
+ :collection => lambda { Mongoid.master.collection('sessions') }
17
+
18
+ But you can of course connect with whatever ORM you prefer.
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2010 Zedkit. See LICENSE for details. http://zedkit.com.
data/Rakefile ADDED
@@ -0,0 +1,69 @@
1
+ ##
2
+ # Copyright (c) Zedkit.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
6
+ # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7
+ # Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ ##
17
+
18
+ require 'rubygems'
19
+ require 'rake'
20
+
21
+ begin
22
+ require 'jeweler'
23
+ Jeweler::Tasks.new do |gem|
24
+ gem.name = "mongo_session_gaggle"
25
+ gem.summary = %Q{Simple MongoDB session store for Rails 3.x}
26
+ gem.description = %Q{Simple MongoDB session store for Rails 3.x. Yup that is what it is.}
27
+
28
+ gem.email = "ejw@zedkit.com"
29
+ gem.homepage = "http://github.com/ejw/mongo_session_gaggle"
30
+ gem.authors = ["Eric Woodward"]
31
+ gem.rubyforge_project = "mongo_session_gaggle"
32
+ gem.files = FileList['[A-Z]*', 'lib/**/*.rb', 'lib/tasks/*.rake', 'test/**/*.rb']
33
+ end
34
+ Jeweler::GemcutterTasks.new
35
+ rescue LoadError
36
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
37
+ end
38
+
39
+ require 'rake/testtask'
40
+ Rake::TestTask.new(:test) do |test|
41
+ test.libs << 'lib' << 'test'
42
+ test.pattern = 'test/**/test_*.rb'
43
+ test.verbose = true
44
+ end
45
+
46
+ begin
47
+ require 'rcov/rcovtask'
48
+ Rcov::RcovTask.new do |test|
49
+ test.libs << 'test'
50
+ test.pattern = 'test/**/test_*.rb'
51
+ test.verbose = true
52
+ end
53
+ rescue LoadError
54
+ task :rcov do
55
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
56
+ end
57
+ end
58
+
59
+ task :test => :check_dependencies
60
+ task :default => :test
61
+
62
+ require 'rake/rdoctask'
63
+ Rake::RDocTask.new do |rdoc|
64
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "mongo_session_gaggle #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ ##
2
+ # Copyright (c) Zedkit.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
6
+ # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7
+ # Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ ##
17
+
18
+ require 'rubygems'
19
+ require 'action_dispatch/middleware/session/abstract_store'
20
+
21
+ require 'mongo'
22
+ require 'mongo_session_gaggle/mongo'
23
+ require 'mongo_session_gaggle/rails_session_store'
@@ -0,0 +1,62 @@
1
+ ##
2
+ # Copyright (c) Zedkit.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
6
+ # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7
+ # Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ ##
17
+
18
+ module MongoSessions
19
+ module MongoStore
20
+ attr_reader :collection
21
+
22
+ def initialize(app, options = {})
23
+ unless options[:collection]
24
+ raise 'Collection is a required option via :collection. This gem does not connect to MongoDB itself. You have to ' <<
25
+ 'handle that for it. Peace.'
26
+ end
27
+ @collection = options[:collection].respond_to?(:call) ? options[:collection].call : options[:collection]
28
+ super
29
+ end
30
+
31
+ private
32
+ def get_session(env, sid)
33
+ vv = nil
34
+ rppp = Benchmark.realtime do
35
+ dd = collection.find_one('_id' => mongo_session_sid(sid))
36
+ vv = [mongo_session_sid(sid), dd ? unpack(dd['ss']) : {}]
37
+ end
38
+ Rails.logger.info "Session GET (#{('%.1f' % (rppp * 1000)) << 'ms'})"
39
+ vv
40
+ end
41
+ def set_session(env, sid, session_data, options = {})
42
+ rppp = Benchmark.realtime do
43
+ collection.update({ '_id' => mongo_session_sid(sid) },
44
+ { '_id' => mongo_session_sid(sid), 'tt' => Time.now, 'ss' => pack(session_data)}, { :upsert => true })
45
+ end
46
+ Rails.logger.info "Session SET (#{('%.1f' % (rppp * 1000)) << 'ms'})"
47
+ sid
48
+ end
49
+
50
+ def pack(data)
51
+ [Marshal.dump(data)].pack('m*')
52
+ end
53
+ def unpack(packed)
54
+ return nil unless packed
55
+ Marshal.load(packed.unpack('m*').first)
56
+ end
57
+ def mongo_session_sid(sid)
58
+ sid ||= generate_sid
59
+ sid
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,24 @@
1
+ ##
2
+ # Copyright (c) Zedkit.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
5
+ # files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
6
+ # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7
+ # Software is furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ # Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
15
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ ##
17
+
18
+ module ActionDispatch
19
+ module Session
20
+ class MongoStore < AbstractStore
21
+ include MongoSessions::MongoStore
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_session_gaggle
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Eric Woodward
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-20 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Simple MongoDB session store for Rails 3.x. Yup that is what it is.
22
+ email: ejw@zedkit.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - LICENSE
32
+ - README.rdoc
33
+ - Rakefile
34
+ - VERSION
35
+ - lib/mongo_session_gaggle.rb
36
+ - lib/mongo_session_gaggle/mongo.rb
37
+ - lib/mongo_session_gaggle/rails_session_store.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/ejw/mongo_session_gaggle
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project: mongo_session_gaggle
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Simple MongoDB session store for Rails 3.x
70
+ test_files: []
71
+