octoshark 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a80290fe7affe4b399c3a48d9676c9f910618fdc
4
- data.tar.gz: 65278830e411768633d4ec5f65e227caea97f52e
3
+ metadata.gz: e36f799c08e10ce190cd98d93fbc9133388f85cc
4
+ data.tar.gz: 4d3b95a2b17155770a2f22c6d0fb7598bb192eda
5
5
  SHA512:
6
- metadata.gz: 3759cd06b0ac6f5f6426287a191dc6c1a6e427b0cc93ef8ddebc998cd413f83cd6147dc9d47f58faaaf580d7e4de63038cec0b78a6ee96aa6bc88709021dc2e8
7
- data.tar.gz: 62b469072a953bf8cd6d62d7e9fd6c9e4517371bfb16fc23b6d7edeab6f0533ee923306f0c118ce3de6e1158e3f5888889ba9ef5f400cdb3f68b544e9d3dfc4a
6
+ metadata.gz: 62ae7717fe0960b31426328514a7bd59ec3084e409dd19cbdcf8f8b10b74348c030b36c3b3afe01c218ad5ee1790842073981f5d662f236b507ec34c7b3b5c1b
7
+ data.tar.gz: 8f639d0260942633132b479193ba1c4105bf1b965929bf57a804e0a3c1ce2aaf7caa190c947ad08d749ac788a1f6fa398ec4c133481c8146b2b78d7e495fefda
@@ -0,0 +1 @@
1
+ 2.1.1
@@ -17,6 +17,7 @@ module Octoshark
17
17
  :disconnect!,
18
18
  :find_connection_pool,
19
19
  :with_connection,
20
+ :without_connection,
20
21
  :current_connection,
21
22
  :current_connection?,
22
23
  to: :switcher
@@ -27,22 +27,21 @@ module Octoshark
27
27
  end
28
28
 
29
29
  def with_connection(name, &block)
30
- result = nil
31
-
32
30
  find_connection_pool(name).with_connection do |connection|
33
- previous_connection = Thread.current[OCTOSHARK]
34
- Thread.current[OCTOSHARK] = connection
35
-
36
31
  connection.connection_name = name
37
32
 
38
- begin
39
- result = yield(connection)
40
- ensure
41
- Thread.current[OCTOSHARK] = previous_connection
33
+ change_connection_reference(connection) do
34
+ yield(connection)
42
35
  end
43
36
  end
37
+ end
44
38
 
45
- result
39
+ def without_connection(&block)
40
+ connection = nil
41
+
42
+ change_connection_reference(connection) do
43
+ yield(connection)
44
+ end
46
45
  end
47
46
 
48
47
  def find_connection_pool(name)
@@ -63,5 +62,16 @@ module Octoshark
63
62
  spec_class = ActiveRecord::Base::ConnectionSpecification
64
63
  end
65
64
  end
65
+
66
+ def change_connection_reference(connection)
67
+ previous_connection = Thread.current[OCTOSHARK]
68
+ Thread.current[OCTOSHARK] = connection
69
+
70
+ begin
71
+ yield
72
+ ensure
73
+ Thread.current[OCTOSHARK] = previous_connection
74
+ end
75
+ end
66
76
  end
67
77
  end
@@ -1,3 +1,3 @@
1
1
  module Octoshark
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -123,6 +123,12 @@ describe Octoshark::ConnectionSwitcher do
123
123
  end
124
124
  end
125
125
 
126
+ it "returns value from execution" do
127
+ switcher = Octoshark::ConnectionSwitcher.new({})
128
+ result = switcher.with_connection(:default) { |connection| connection.execute("SELECT 1") }
129
+ expect(result).to eq([{"1"=>1, 0=>1}])
130
+ end
131
+
126
132
  it "raises Octoshark::NoConnectionError" do
127
133
  switcher = Octoshark::ConnectionSwitcher.new({})
128
134
 
@@ -130,6 +136,22 @@ describe Octoshark::ConnectionSwitcher do
130
136
  end
131
137
  end
132
138
 
139
+ describe '#without_connection' do
140
+ it "can reset current connection temporarily inside nested connection block" do
141
+ switcher = Octoshark::ConnectionSwitcher.new({})
142
+
143
+ switcher.with_connection(:default) do |connection|
144
+ expect(db(switcher.current_connection)).to eq("default")
145
+
146
+ switcher.without_connection do |connection|
147
+ expect { switcher.current_connection }.to raise_error(Octoshark::NoCurrentConnectionError)
148
+ end
149
+
150
+ expect(db(switcher.current_connection)).to eq("default")
151
+ end
152
+ end
153
+ end
154
+
133
155
  describe "#disconnect!" do
134
156
  it "removes all connections from connection pools" do
135
157
  switcher = Octoshark::ConnectionSwitcher.new({})
@@ -78,6 +78,7 @@ describe Octoshark do
78
78
  :disconnect!,
79
79
  :find_connection_pool,
80
80
  :with_connection,
81
+ :without_connection,
81
82
  ].each do |method_name|
82
83
  describe ".#{method_name}" do
83
84
  it "delegates #{method_name} to connection switcher" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octoshark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dalibor Nasevic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -103,6 +103,7 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
105
  - ".rspec"
106
+ - ".ruby-version"
106
107
  - ".travis.yml"
107
108
  - Appraisals
108
109
  - Gemfile