rack-session-dbm 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'rack', ">= 1.1.0"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.3.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ end
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rack (1.3.2)
11
+ rake (0.9.2)
12
+ rcov (0.9.10)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.6.4)
28
+ rack (>= 1.1.0)
29
+ rcov
30
+ rspec (~> 2.3.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 udzura
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.
@@ -0,0 +1,27 @@
1
+ = rack-session-gdbm
2
+
3
+ A Rack-based session store with GDBM. Take it easy to use sessions!
4
+
5
+ == Introduction
6
+
7
+ * install libgdbm-dev or something like that before you build ruby
8
+ * (re)install ruby or run setup.rb on your gdbm lib dir
9
+ * use Rack::Session::GDBM(, CUSTOMIZED_GDBM_FILE_PATH)
10
+
11
+ TODO more complete manual...
12
+
13
+ == Contributing to rack-session-gdbm
14
+
15
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
16
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
17
+ * Fork the project
18
+ * Start a feature/bugfix branch
19
+ * Commit and push until you are happy with your contribution
20
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
+ * 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.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2011 Uchio Kondo <udzura__atmark__udzura.jp>. See LICENSE.txt for
26
+ further details.
27
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rack-session-dbm"
18
+ gem.homepage = "http://github.com/udzura/rack-session-dbm"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A rack-based session store on sdbm/gdbm}
21
+ gem.description = %Q{A rack-based session store on sdbm/gdbm. you can use this gem in smaller projects.}
22
+ gem.email = "udzura@udzura.jp"
23
+ gem.authors = ["Uchio Kondo"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rake/rdoctask'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "rack-session-dbm #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,6 @@
1
+ module Rack
2
+ module Session
3
+ autoload :GDBM, 'rack/session/gdbm'
4
+ autoload :SDBM, 'rack/session/sdbm'
5
+ end
6
+ end
@@ -0,0 +1,67 @@
1
+ require 'rack/session/abstract/id'
2
+
3
+ module Rack
4
+ module Session
5
+ class AbstractDBM < Abstract::ID
6
+ attr_reader :mutex, :pool
7
+
8
+ def initialize(app, path=nil, options={})
9
+ super(app, options)
10
+
11
+ @mutex = Mutex.new
12
+ db_path = path || (ENV['RACK_ROOT'] ? ::File.join(ENV['RACK_ROOT'], 'tmp', default_session_file) : @default_options[:dbm_path])
13
+ opts = @default_options
14
+
15
+ @pool = dbklass.new(db_path)
16
+ end
17
+
18
+ def generate_sid
19
+ loop do
20
+ sid = super
21
+ break sid unless @pool[sid]
22
+ end
23
+ end
24
+
25
+ def get_session(env, sid)
26
+ with_lock(env, [nil, {}]) do
27
+ unless sid and session = Marshal.load(@pool[sid] || "\x04\b0")
28
+ sid, session = generate_sid, {}
29
+ begin
30
+ @pool[sid] = Marshal.dump(session)
31
+ rescue
32
+ raise "Session collision on '#{sid.inspect}'"
33
+ end
34
+ end
35
+ [sid, session]
36
+ end
37
+ end
38
+
39
+ def set_session(env, session_id, new_session, options)
40
+ with_lock(env, false) do
41
+ @pool[session_id] = Marshal.dump(new_session)
42
+ session_id
43
+ end
44
+ end
45
+
46
+ def destroy_session(env, session_id, options)
47
+ with_lock(env) do
48
+ @pool.delete(session_id)
49
+ generate_sid unless options[:drop]
50
+ end
51
+ end
52
+
53
+ def with_lock(env, default=nil)
54
+ @mutex.lock if env['rack.multithread']
55
+ yield
56
+ rescue StandardError
57
+ if $VERBOSE
58
+ warn "#{self} is unable to write to dbm."
59
+ warn $!.inspect
60
+ end
61
+ default
62
+ ensure
63
+ @mutex.unlock if @mutex.locked?
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,18 @@
1
+ require 'gdbm'
2
+ require 'rack/session/abstract_dbm'
3
+
4
+ module Rack
5
+ module Session
6
+ class GDBM < AbstractDBM
7
+ DEFAULT_OPTIONS =
8
+ Abstract::ID::DEFAULT_OPTIONS.merge :dbm_path => ::File.join((ENV['TMP_PATH'] || ENV['TMP'] || '/tmp'), "sessions.gdbm")
9
+ def dbklass
10
+ ::GDBM
11
+ end
12
+
13
+ def default_session_file
14
+ "sessions.gdbm"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'sdbm'
2
+ require 'rack/session/abstract_dbm'
3
+
4
+ module Rack
5
+ module Session
6
+ class SDBM < AbstractDBM
7
+ DEFAULT_OPTIONS =
8
+ Abstract::ID::DEFAULT_OPTIONS.merge :dbm_path => ::File.join((ENV['TMP_PATH'] || ENV['TMP'] || '/tmp'), "sessions.sdbm")
9
+
10
+ def dbklass
11
+ ::SDBM
12
+ end
13
+
14
+ def default_session_file
15
+ "sessions.sdbm"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack-session-dbm}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Uchio Kondo"]
12
+ s.date = %q{2011-08-23}
13
+ s.description = %q{A rack-based session store on sdbm/gdbm. you can use this gem in smaller projects.}
14
+ s.email = %q{udzura@udzura.jp}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/rack-session-dbm.rb",
29
+ "lib/rack/session/abstract_dbm.rb",
30
+ "lib/rack/session/gdbm.rb",
31
+ "lib/rack/session/sdbm.rb",
32
+ "rack-session-dbm.gemspec",
33
+ "spec/rack-session-sdbm_spec.rb",
34
+ "spec/spec_helper.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/udzura/rack-session-dbm}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.6.2}
40
+ s.summary = %q{A rack-based session store on sdbm/gdbm}
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<rack>, [">= 1.1.0"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rack>, [">= 1.1.0"])
53
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rack>, [">= 1.1.0"])
60
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Rack::Session::SDBM do
4
+ before do
5
+ @session_key = Rack::Session::SDBM::DEFAULT_OPTIONS[:key]
6
+ @path = '/tmp/test-session.sdbm'
7
+ @dbm = SDBM.new(@path)
8
+
9
+ @increment_mockapp = lambda do |env|
10
+ env['rack.session']['counter'] ||= 0
11
+ env['rack.session']['counter'] += 1
12
+ Rack::Response.new(env['rack.session'].inspect).finish
13
+ end
14
+ end
15
+
16
+ it "creates a new cookie" do
17
+ pool = Rack::Session::SDBM.new(@increment_mockapp, @path)
18
+ res = Rack::MockRequest.new(pool).get('/')
19
+ res['Set-Cookie'].should match(/#{@session_key}=/)
20
+ res.body.should == '{"counter"=>1}'
21
+ end
22
+
23
+ it 'determines session from a cookie' do
24
+ pool = Rack::Session::SDBM.new(@increment_mockapp, @path)
25
+ req = Rack::MockRequest.new(pool)
26
+ res = req.get('/')
27
+ cookie = res['Set-Cookie']
28
+ req.get('/', 'HTTP_COOKIE' => cookie).
29
+ body.should == '{"counter"=>2}'
30
+ req.get('/', 'HTTP_COOKIE' => cookie).
31
+ body.should == '{"counter"=>3}'
32
+ end
33
+
34
+ =begin
35
+ it "" do
36
+ end
37
+ =end
38
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rack-session-dbm'
5
+
6
+ require 'rack/mock'
7
+ require 'rack/response'
8
+ require 'thread'
9
+
10
+ # Requires supporting files with custom matchers and macros, etc,
11
+ # in ./support/ and its subdirectories.
12
+ #Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-session-dbm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Uchio Kondo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-23 00:00:00.000000000 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ requirement: &24855720 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *24855720
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &24855240 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *24855240
37
+ - !ruby/object:Gem::Dependency
38
+ name: bundler
39
+ requirement: &24854760 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.0.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *24854760
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &24854280 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.6.4
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *24854280
59
+ - !ruby/object:Gem::Dependency
60
+ name: rcov
61
+ requirement: &24853800 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *24853800
70
+ description: A rack-based session store on sdbm/gdbm. you can use this gem in smaller
71
+ projects.
72
+ email: udzura@udzura.jp
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files:
76
+ - LICENSE.txt
77
+ - README.rdoc
78
+ files:
79
+ - .document
80
+ - .rspec
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ - Rakefile
86
+ - VERSION
87
+ - lib/rack-session-dbm.rb
88
+ - lib/rack/session/abstract_dbm.rb
89
+ - lib/rack/session/gdbm.rb
90
+ - lib/rack/session/sdbm.rb
91
+ - rack-session-dbm.gemspec
92
+ - spec/rack-session-sdbm_spec.rb
93
+ - spec/spec_helper.rb
94
+ has_rdoc: true
95
+ homepage: http://github.com/udzura/rack-session-dbm
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 2371025864029867347
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.6.2
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: A rack-based session store on sdbm/gdbm
123
+ test_files: []