with_connection 0.1.15 → 0.1.16

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.15
1
+ 0.1.16
@@ -9,7 +9,13 @@ module WithConnection
9
9
  end
10
10
 
11
11
  def with_connection(key=nil, &block)
12
- pool_for_key(key).with_connection(&block)
12
+ local_current[:pool] = pool_for_key(key)
13
+ local_current[:pool].with_connection(&block)
14
+ end
15
+
16
+ def connection
17
+ local_current[:pool] ||= @default_pool
18
+ local_current[:pool].connection
13
19
  end
14
20
 
15
21
  def pool_for_key(key)
@@ -19,6 +25,10 @@ module WithConnection
19
25
  (@list.detect { |item| item.include?(key) } || @default_pool)
20
26
  end
21
27
 
28
+ def local_current
29
+ defined?(EM) && EM.reactor_running? ? Fiber.current : Thread.current
30
+ end
31
+
22
32
  class Item
23
33
  attr_reader :range, :pool
24
34
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "with_connection"
8
- s.version = "0.1.15"
8
+ s.version = "0.1.16"
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"]
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.15
4
+ version: 0.1.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: 1570921479752870444
118
+ hash: 4570418571159879267
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  none: false
121
121
  requirements: