octoshark 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Appraisals +12 -0
- data/gemfiles/rails3.1.gemfile +7 -0
- data/gemfiles/rails3.2.gemfile +7 -0
- data/gemfiles/rails4.1.gemfile +7 -0
- data/lib/octoshark.rb +1 -1
- data/lib/octoshark/active_record_extensions.rb +8 -12
- data/lib/octoshark/connection_switcher.rb +5 -11
- data/lib/octoshark/version.rb +1 -1
- data/spec/octoshark/active_record_extensions_spec.rb +17 -1
- data/spec/octoshark/connection_switcher_spec.rb +0 -16
- data/spec/octoshark_spec.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90a3eb977595f681e0fffb0fe11387a0bfd14a5f
|
4
|
+
data.tar.gz: 2eb1ddcefcd71470ab1f6f0271b854b3294b9874
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f317a576062bdee24ca65433969742ec7d86890af9f936d6fa6241bd69e5e4486dfa06e2de5bcac6f2c639c4946c9b25fd144db7afdfc29478cee5ff4b0db991
|
7
|
+
data.tar.gz: d27b2fdafc8a99bd78ac69e80152e509710908ebc5116451128c732ef793f79d5ad852dc4c47df3dfc757d21ec710996b4f4ff97f000d9f3df34230845e4763b
|
data/.travis.yml
CHANGED
data/Appraisals
CHANGED
@@ -2,6 +2,18 @@ appraise "rails3" do
|
|
2
2
|
gem "activerecord", "~> 3.0.0"
|
3
3
|
end
|
4
4
|
|
5
|
+
appraise "rails3.1" do
|
6
|
+
gem "activerecord", "~> 3.1.0"
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails3.2" do
|
10
|
+
gem "activerecord", "~> 3.2.0"
|
11
|
+
end
|
12
|
+
|
5
13
|
appraise "rails4" do
|
6
14
|
gem "activerecord", "~> 4.0.0"
|
7
15
|
end
|
16
|
+
|
17
|
+
appraise "rails4.1" do
|
18
|
+
gem "activerecord", "~> 4.1.0"
|
19
|
+
end
|
data/lib/octoshark.rb
CHANGED
@@ -15,7 +15,7 @@ module Octoshark
|
|
15
15
|
delegate :current_connection, :with_connection,
|
16
16
|
:connection, :current_or_default_connection,
|
17
17
|
:connection_pools, :find_connection_pool,
|
18
|
-
:
|
18
|
+
:disconnect!, to: :switcher
|
19
19
|
|
20
20
|
def configure(configs)
|
21
21
|
@configs = configs
|
@@ -16,22 +16,18 @@ module Octoshark
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
module
|
20
|
-
|
19
|
+
module ActiveRecordAbstractAdapter
|
20
|
+
attr_accessor :connection_name
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def log(sql, name = "SQL", *other_args)
|
23
|
+
if connection_name
|
24
|
+
name = "[Octoshark: #{connection_name}] #{name}"
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
prefix = if Octoshark.configured? && Octoshark.current_connection_name
|
28
|
-
color("[Octoshark: #{Octoshark.current_connection_name}]",
|
29
|
-
ActiveSupport::LogSubscriber::GREEN, true)
|
30
|
-
end
|
31
|
-
debug_without_octoshark("#{prefix}#{msg}")
|
27
|
+
super(sql, name, *other_args)
|
32
28
|
end
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
32
|
ActiveRecord::Base.send(:include, Octoshark::ActiveRecordBase)
|
37
|
-
ActiveRecord::
|
33
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:prepend, Octoshark::ActiveRecordAbstractAdapter)
|
@@ -15,15 +15,11 @@ module Octoshark
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def current_connection
|
18
|
-
|
18
|
+
Thread.current[OCTOSHARK] || raise(NoCurrentConnectionError, "No current connection, use Octoshark.with_connection")
|
19
19
|
end
|
20
20
|
|
21
21
|
def current_or_default_connection
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def current_connection_name
|
26
|
-
current_details[:name]
|
22
|
+
Thread.current[OCTOSHARK] || @default_pool.connection
|
27
23
|
end
|
28
24
|
|
29
25
|
def with_connection(name, &block)
|
@@ -31,7 +27,9 @@ module Octoshark
|
|
31
27
|
|
32
28
|
find_connection_pool(name).with_connection do |connection|
|
33
29
|
previous_connection = Thread.current[OCTOSHARK]
|
34
|
-
Thread.current[OCTOSHARK] =
|
30
|
+
Thread.current[OCTOSHARK] = connection
|
31
|
+
|
32
|
+
connection.connection_name = name
|
35
33
|
|
36
34
|
begin
|
37
35
|
result = yield(connection)
|
@@ -61,9 +59,5 @@ module Octoshark
|
|
61
59
|
spec_class = ActiveRecord::Base::ConnectionSpecification
|
62
60
|
end
|
63
61
|
end
|
64
|
-
|
65
|
-
def current_details
|
66
|
-
Thread.current[OCTOSHARK] || {}
|
67
|
-
end
|
68
62
|
end
|
69
63
|
end
|
data/lib/octoshark/version.rb
CHANGED
@@ -8,7 +8,7 @@ describe "ActiveRecord Extensions" do
|
|
8
8
|
spec = ActiveRecord::Base.remove_connection
|
9
9
|
ActiveRecord::Base.establish_connection(spec)
|
10
10
|
|
11
|
-
expect(
|
11
|
+
expect(Octoshark.find_connection_pool(:default)).to eq(ActiveRecord::Base.connection_pool)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "logs current connection name" do
|
@@ -26,4 +26,20 @@ describe "ActiveRecord Extensions" do
|
|
26
26
|
|
27
27
|
ActiveRecord::Base.logger = nil
|
28
28
|
end
|
29
|
+
|
30
|
+
it "logs the connection name for the Octoshark connection only" do
|
31
|
+
io = StringIO.new
|
32
|
+
logger = Logger.new(io)
|
33
|
+
|
34
|
+
ActiveRecord::Base.logger = logger
|
35
|
+
|
36
|
+
Octoshark.configure(configs)
|
37
|
+
Octoshark.with_connection(:db1) do |connection|
|
38
|
+
ActiveRecord::Base.connection.execute("SELECT 1")
|
39
|
+
end
|
40
|
+
|
41
|
+
expect(io.string).not_to include('[Octoshark: db1]')
|
42
|
+
|
43
|
+
ActiveRecord::Base.logger = nil
|
44
|
+
end
|
29
45
|
end
|
@@ -57,22 +57,6 @@ describe Octoshark::ConnectionSwitcher do
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
describe "#current_connection_name" do
|
61
|
-
it "returns current connection" do
|
62
|
-
switcher = Octoshark::ConnectionSwitcher.new(configs)
|
63
|
-
|
64
|
-
switcher.with_connection(:db1) do |connection|
|
65
|
-
expect(switcher.current_connection_name).to eq(:db1)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
it "returns nil when no current connection" do
|
70
|
-
switcher = Octoshark::ConnectionSwitcher.new
|
71
|
-
|
72
|
-
expect(switcher.current_connection_name).to be_nil
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
60
|
describe '#find_connection_pool' do
|
77
61
|
it "can find connection pool by name" do
|
78
62
|
switcher = Octoshark::ConnectionSwitcher.new(configs)
|
data/spec/octoshark_spec.rb
CHANGED
@@ -74,7 +74,7 @@ describe Octoshark do
|
|
74
74
|
:current_connection, :with_connection,
|
75
75
|
:connection, :current_or_default_connection,
|
76
76
|
:connection_pools, :find_connection_pool,
|
77
|
-
:
|
77
|
+
:disconnect!
|
78
78
|
].each do |method_name|
|
79
79
|
describe ".#{method_name}" do
|
80
80
|
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.
|
4
|
+
version: 0.0.6
|
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-07-
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -109,7 +109,10 @@ files:
|
|
109
109
|
- LICENSE.txt
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
|
+
- gemfiles/rails3.1.gemfile
|
113
|
+
- gemfiles/rails3.2.gemfile
|
112
114
|
- gemfiles/rails3.gemfile
|
115
|
+
- gemfiles/rails4.1.gemfile
|
113
116
|
- gemfiles/rails4.gemfile
|
114
117
|
- lib/octoshark.rb
|
115
118
|
- lib/octoshark/active_record_extensions.rb
|