with_connection 0.1.14 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.14
1
+ 0.1.15
@@ -0,0 +1,48 @@
1
+ module WithConnection
2
+ class RangedConnectionPool
3
+ attr_reader :list, :default_pool, :key_algo
4
+
5
+ def initialize(ranges_and_pools, default_pool, key_algo)
6
+ @list = ranges_and_pools.map { |range, pool| Item.new(range, pool) }
7
+ @default_pool = default_pool
8
+ @key_algo = key_algo
9
+ end
10
+
11
+ def with_connection(key=nil, &block)
12
+ pool_for_key(key).with_connection(&block)
13
+ end
14
+
15
+ def pool_for_key(key)
16
+ key = self.key_algo.call(key) if key
17
+ key.nil? ?
18
+ @default_pool :
19
+ (@list.detect { |item| item.include?(key) } || @default_pool)
20
+ end
21
+
22
+ class Item
23
+ attr_reader :range, :pool
24
+
25
+ def initialize(range, pool)
26
+ @range = range
27
+ @pool = pool
28
+ end
29
+
30
+ def include?(key)
31
+ @range.include? key
32
+ end
33
+ end
34
+
35
+ class BasicRange
36
+ attr_reader :lo, :hi
37
+
38
+ def initialize(lo, hi)
39
+ @lo = lo
40
+ @hi = hi
41
+ end
42
+
43
+ def include?(val)
44
+ val >= lo && val <= hi
45
+ end
46
+ end
47
+ end
48
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "with_connection"
8
- s.version = "0.1.14"
8
+ s.version = "0.1.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Doug Youch"]
12
- s.date = "2013-06-19"
12
+ s.date = "2013-06-22"
13
13
  s.description = "Uses active record connection pool logic with the fiber_patch"
14
14
  s.email = "doug@sessionm.com"
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/dalli/async_socket.rb",
33
33
  "lib/with_connection.rb",
34
34
  "lib/with_connection/connection_pool.rb",
35
+ "lib/with_connection/ranged_connection_pool.rb",
35
36
  "with_connection.gemspec"
36
37
  ]
37
38
  s.homepage = "http://github.com/dyouch5@yahoo.com/with_connection"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: with_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-19 00:00:00.000000000 Z
12
+ date: 2013-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -98,6 +98,7 @@ files:
98
98
  - lib/dalli/async_socket.rb
99
99
  - lib/with_connection.rb
100
100
  - lib/with_connection/connection_pool.rb
101
+ - lib/with_connection/ranged_connection_pool.rb
101
102
  - with_connection.gemspec
102
103
  homepage: http://github.com/dyouch5@yahoo.com/with_connection
103
104
  licenses:
@@ -114,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
115
  version: '0'
115
116
  segments:
116
117
  - 0
117
- hash: 4002178996302934414
118
+ hash: 1570921479752870444
118
119
  required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  none: false
120
121
  requirements: