keymap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ module Keymap
2
+
3
+ # Generic Keymap exception class.
4
+ class KeymapError < StandardError
5
+ end
6
+
7
+ # Raised when adapter not specified on connection (or configuration file <tt>config/database.yml</tt>
8
+ # misses adapter field).
9
+ class AdapterNotSpecified < KeymapError
10
+ end
11
+
12
+ # Raised when Keymap cannot find database adapter specified in <tt>config/database.yml</tt> or programmatically.
13
+ class AdapterNotFound < KeymapError
14
+ end
15
+
16
+ # Raised when connection to the database could not been established (for example when <tt>connection=</tt>
17
+ # is given a nil object).
18
+ class ConnectionNotEstablished < KeymapError
19
+ end
20
+
21
+ # The library uses this exception to distinguish a deliberate rollback from other
22
+ # exceptional situations. Normally, raising an exception will cause the
23
+ # +transaction+ method to rollback the database transaction *and* pass on the
24
+ # exception. But if you raise a Rollback exception, then the database transaction
25
+ # will be rolled back, without passing on the exception.
26
+ class Rollback < KeymapError
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module Keymap
2
+ VERSION = "0.1.0"
3
+ end
File without changes
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Keymap::ConnectionAdapters::ConnectionPool do
4
+ before do
5
+ @adapter = Keymap::ConnectionAdapters::AbstractAdapter.new nil, nil
6
+ @pool = Keymap::ConnectionAdapters::ConnectionPool.new(Keymap::Base::ConnectionSpecification.new({}, nil))
7
+ @pool.connections << @adapter
8
+ @adapter.pool = @pool
9
+ end
10
+
11
+ context "a pool manages connections" do
12
+ it "marks the connections in use when checked out" do
13
+ @adapter.should eq(@pool.connection)
14
+ @adapter.in_use?.should be_true
15
+ end
16
+ it "marks the connection not in use when checked in" do
17
+ @adapter.close
18
+ !@adapter.in_use?.should be_false
19
+ end
20
+ it "returns the same connection upon subsequent checkouts if only one connection is pooled" do
21
+ @adapter.should eq(@pool.connection)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ require 'spec_helper'
@@ -0,0 +1,2 @@
1
+ --exclude
2
+ spec,bin,/Library/Ruby
@@ -0,0 +1,3 @@
1
+ -c
2
+ -b
3
+ -fs
@@ -0,0 +1,19 @@
1
+ $:.unshift File.expand_path("../..", __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'rspec/mocks'
5
+
6
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
7
+ $:.unshift(File.expand_path("../lib", __FILE__))
8
+ $:.unshift(File.dirname(__FILE__))
9
+
10
+ require 'active_support'
11
+ require 'keymap'
12
+ require 'simplecov'
13
+
14
+ SimpleCov.start do
15
+ add_group 'Libraries', 'lib'
16
+ end
17
+
18
+ #RSpec.configure do |config|
19
+ #end
@@ -0,0 +1,45 @@
1
+ require 'yaml'
2
+ require 'erubis'
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ SPEC_ROOT = File.expand_path(File.dirname(__FILE__))
7
+
8
+ module KeymapTest
9
+ class << self
10
+ def config
11
+ @config ||= read_config
12
+ end
13
+
14
+ private
15
+
16
+ def config_file
17
+ Pathname.new(ENV['KEYMAP_CONFIG'] || SPEC_ROOT + '/support/config.yml')
18
+ end
19
+
20
+ def read_config
21
+ unless config_file.exist?
22
+ FileUtils.cp SPEC_ROOT + '/support/config.example.yml', config_file
23
+ end
24
+
25
+ erb = Erubis::Eruby.new(config_file.read)
26
+ expand_config(YAML.parse(erb.result(binding)).transform)
27
+ end
28
+
29
+ def expand_config(config)
30
+ config['connections'].each do |adapter, connection|
31
+ dbs = [['arunit', 'activerecord_unittest'], ['arunit2', 'activerecord_unittest2']]
32
+ dbs.each do |name, dbname|
33
+ unless connection[name].is_a?(Hash)
34
+ connection[name] = {'database' => connection[name]}
35
+ end
36
+
37
+ connection[name]['database'] ||= dbname
38
+ connection[name]['adapter'] ||= adapter
39
+ end
40
+ end
41
+
42
+ config
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ default_connection: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %>
2
+
3
+ with_manual_interventions: false
4
+
5
+ connections:
6
+ redis:
7
+ adapter: redis
8
+ host: localhost
9
+ password: kmunit
10
+ database: kmunit
@@ -0,0 +1,17 @@
1
+ require 'logger'
2
+
3
+ module KeymapTest
4
+ def self.connection_name
5
+ ENV['KEYMAP_CONN'] || config['default_connection']
6
+ end
7
+
8
+ def self.connection_config
9
+ config['connections'][connection_name]
10
+ end
11
+
12
+ def self.connect
13
+ Keymap::Base.logger = Logger.new("debug.log")
14
+ Keymap::Base.configurations = connection_config
15
+ Keymap::Base.establish_connection 'kmunit'
16
+ end
17
+ end
File without changes
@@ -0,0 +1,89 @@
1
+ require 'rubygems'
2
+ require 'keymap'
3
+ require 'yaml'
4
+ require 'logger'
5
+
6
+ Keymap::Base.configurations['redis'] = {
7
+ :adapter => 'redis',
8
+ :host => 'localhost'
9
+ }
10
+
11
+ class User < Keymap::Base
12
+
13
+ establish_connection 'redis'
14
+
15
+ def test
16
+ c = self.connection
17
+ puts 'hi'
18
+ end
19
+ end
20
+
21
+ user = User.new
22
+ user.test
23
+
24
+ #
25
+ #config = {adapter: 'redis',
26
+ # host: 'localhost'
27
+ # #database: database,
28
+ # #username: user,
29
+ # #password: password,
30
+ #}
31
+ #Keymap::Base.establish_connection(config)
32
+ #Keymap::Base.logger = Logger.new(STDERR)
33
+ #
34
+ #class User < Keymap::Base
35
+ #end
36
+
37
+ #puts User.count
38
+ # SQL (0.000277) SELECT count(*) AS count_all FROM users
39
+ # 6
40
+
41
+
42
+ #require 'redis'
43
+ #require 'keymap/connection_adapters/redis_adapter'
44
+ #require 'keymap/connection_adapters/abstract/connection_specification'
45
+ #
46
+ #Base.configurations["redis"] = {
47
+ # :adapter => 'redis',
48
+ # :host => 'localhost'
49
+ #}
50
+ #
51
+ #Base.establish_connection(
52
+ # :adapter => "redis",
53
+ # :host => "localhost"
54
+ #)
55
+ #
56
+ #
57
+ ##
58
+ ##class Table1 < ActiveRecord::Base
59
+ ## establish_connection "db1"
60
+ ##end
61
+ ##
62
+ ##class Table2 < ActiveRecord::Base
63
+ ## establish_connection "db2"
64
+ ##end
65
+ #
66
+ #
67
+ #redis = ConnectionAdapters::RedisAdapter.new nil, nil, {host: "localhost"}
68
+ #puts redis.active?
69
+ #
70
+ #redis.reconnect!
71
+ #puts redis.active?
72
+ #
73
+ #redis.transaction do
74
+ # tokens = redis.hash 'tokens'
75
+ # tokens[:auth] = 'no way'
76
+ # puts tokens[:auth]
77
+ #end
78
+ #
79
+ #redis.transaction do
80
+ # tokens = redis.hash 'tokens'
81
+ # tokens.each do |key, value|
82
+ # puts "#{key},#{value}"
83
+ # end
84
+ #end
85
+ #
86
+ #redis.disconnect!
87
+ #puts redis.active?
88
+ #
89
+ #
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ GEM_ROOT = File.expand_path(File.join(File.dirname(__FILE__), ".."))
5
+
6
+ begin
7
+
8
+ require 'rspec/core/rake_task'
9
+
10
+ task :default => :spec
11
+
12
+ desc "Run all specs in spec directory"
13
+ RSpec::Core::RakeTask.new(:spec) do |t|
14
+ t.rspec_opts = ['--options', "\"#{GEM_ROOT}/.rspec\""]
15
+ t.pattern = FileList['spec/**/*_spec.rb']
16
+ end
17
+
18
+ desc "Run all functional specs (in functional/ directory)"
19
+ RSpec::Core::RakeTask.new(:functional) do |t|
20
+ t.rspec_opts = ['--options', "\"#{GEM_ROOT}/spec/spec.opts\""]
21
+ t.pattern = FileList['spec/functional/**/*_spec.rb']
22
+ end
23
+
24
+ desc "Run the rspec tests with activesupport loaded"
25
+ RSpec::Core::RakeTask.new(:spec_activesupport) do |t|
26
+ t.rspec_opts = ['--options', "\"#{GEM_ROOT}/.rspec\"", "--require active_support/core_ext"]
27
+ t.pattern = FileList['spec/unit/**/*_spec.rb']
28
+ end
29
+
30
+ namespace :spec do
31
+ #desc "Run all specs in spec directory with RCov"
32
+ #RSpec::Core::RakeTask.new(:cov) do |t|
33
+ # require 'simplecov'
34
+ # SimpleCov.start do
35
+ # add_group 'Libraries', 'lib'
36
+ # end
37
+ #end
38
+
39
+ desc "Print Specdoc for all specs"
40
+ RSpec::Core::RakeTask.new(:doc) do |t|
41
+ t.rspec_opts = %w(--format specdoc --dry-run)
42
+ t.pattern = FileList['spec/**/*_spec.rb']
43
+ end
44
+
45
+ [:unit].each do |sub|
46
+ desc "Run the specs under spec/#{sub}"
47
+ RSpec::Core::RakeTask.new(sub) do |t|
48
+ t.rspec_opts = ['--options', "\"#{GEM_ROOT}/spec/spec.opts\""]
49
+ t.pattern = FileList["spec/#{sub}/**/*_spec.rb"]
50
+ end
51
+ end
52
+ end
53
+
54
+ rescue LoadError
55
+ STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
56
+ end
metadata ADDED
@@ -0,0 +1,247 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keymap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Buck
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: erubis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.7.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: 2.7.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.2
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: 3.0.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: activesupport
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.2.8
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: 3.2.8
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
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: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rdoc
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
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rspec
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 2.11.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 2.11.0
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec-core
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 2.11.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 2.11.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: rspec-expectations
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 2.11.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 2.11.0
158
+ - !ruby/object:Gem::Dependency
159
+ name: rspec-mocks
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ~>
164
+ - !ruby/object:Gem::Version
165
+ version: 2.11.0
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 2.11.0
174
+ description: ActiveRecord like Key-Value Store API for Ruby
175
+ email: buck.robert.j@gmail.com
176
+ executables: []
177
+ extensions: []
178
+ extra_rdoc_files: []
179
+ files:
180
+ - .gitignore
181
+ - .rspec
182
+ - Gemfile
183
+ - LICENSE.txt
184
+ - README.md
185
+ - Rakefile
186
+ - keymap.gemspec
187
+ - lib/keymap.rb
188
+ - lib/keymap/base.rb
189
+ - lib/keymap/connection_adapters/abstract/connection_pool.rb
190
+ - lib/keymap/connection_adapters/abstract/connection_specification.rb
191
+ - lib/keymap/connection_adapters/abstract/transaction_management.rb
192
+ - lib/keymap/connection_adapters/abstract_adapter.rb
193
+ - lib/keymap/connection_adapters/redis_adapter.rb
194
+ - lib/keymap/errors.rb
195
+ - lib/keymap/version.rb
196
+ - spec/data/.gitignore
197
+ - spec/functional/abstract_adapter_spec.rb
198
+ - spec/functional/adapter_spec.rb
199
+ - spec/functional/adapters/redis/connection_spec.rb
200
+ - spec/rcov.opts
201
+ - spec/spec.opts
202
+ - spec/spec_helper.rb
203
+ - spec/support/config.rb
204
+ - spec/support/config.yml
205
+ - spec/support/connection.rb
206
+ - spec/unit/.gitignore
207
+ - spec/unit/test.rb
208
+ - tasks/rspec.rb
209
+ homepage: https://github.com/rbuck/keymap
210
+ licenses: []
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ none: false
217
+ requirements:
218
+ - - ! '>='
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ none: false
223
+ requirements:
224
+ - - ! '>='
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubyforge_project:
229
+ rubygems_version: 1.8.24
230
+ signing_key:
231
+ specification_version: 3
232
+ summary: Abstracts choosing a key-value store implementation, and provides a common
233
+ API.
234
+ test_files:
235
+ - spec/data/.gitignore
236
+ - spec/functional/abstract_adapter_spec.rb
237
+ - spec/functional/adapter_spec.rb
238
+ - spec/functional/adapters/redis/connection_spec.rb
239
+ - spec/rcov.opts
240
+ - spec/spec.opts
241
+ - spec/spec_helper.rb
242
+ - spec/support/config.rb
243
+ - spec/support/config.yml
244
+ - spec/support/connection.rb
245
+ - spec/unit/.gitignore
246
+ - spec/unit/test.rb
247
+ - tasks/rspec.rb