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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 920e18506d2e0b50577f3be766712eac70beec32
4
- data.tar.gz: f8748e37f5a862a547caa5b170d72c352a942582
3
+ metadata.gz: 90a3eb977595f681e0fffb0fe11387a0bfd14a5f
4
+ data.tar.gz: 2eb1ddcefcd71470ab1f6f0271b854b3294b9874
5
5
  SHA512:
6
- metadata.gz: e156d431037b1a543b86b5ccd2de0cbadc3f6698233cab5509f08c99e033f3214cac61e87d2cf661862bc725e41eda13a999113ff3bbc0202d8e610935fb9d64
7
- data.tar.gz: e190b0f3a02d968dd4d4e857c6eea3ff757e9042760afa29d69f1888a07ce7a3170ee734ea25b395c3ffb63a09d8d8aa5f01367aabf04db5ddda60076d8be58f
6
+ metadata.gz: f317a576062bdee24ca65433969742ec7d86890af9f936d6fa6241bd69e5e4486dfa06e2de5bcac6f2c639c4946c9b25fd144db7afdfc29478cee5ff4b0db991
7
+ data.tar.gz: d27b2fdafc8a99bd78ac69e80152e509710908ebc5116451128c732ef793f79d5ad852dc4c47df3dfc757d21ec710996b4f4ff97f000d9f3df34230845e4763b
@@ -7,5 +7,8 @@ notifications:
7
7
  - dalibor.nasevic@gmail.com
8
8
  gemfile:
9
9
  - gemfiles/rails3.gemfile
10
+ - gemfiles/rails3.1.gemfile
11
+ - gemfiles/rails3.2.gemfile
10
12
  - gemfiles/rails4.gemfile
13
+ - gemfiles/rails4.1.gemfile
11
14
  script: bundle exec rspec spec
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
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 3.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -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
- :current_connection_name, :disconnect!, to: :switcher
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 ActiveRecordLogSubscriber
20
- extend ActiveSupport::Concern
19
+ module ActiveRecordAbstractAdapter
20
+ attr_accessor :connection_name
21
21
 
22
- included do
23
- alias_method_chain :debug, :octoshark
24
- end
22
+ def log(sql, name = "SQL", *other_args)
23
+ if connection_name
24
+ name = "[Octoshark: #{connection_name}] #{name}"
25
+ end
25
26
 
26
- def debug_with_octoshark(msg)
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::LogSubscriber.send(:include, Octoshark::ActiveRecordLogSubscriber)
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
- current_details[:connection] || raise(NoCurrentConnectionError, "No current connection, use Octoshark.with_connection")
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
- current_details[:connection] || @default_pool.connection
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] = { name: name, connection: connection }
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
@@ -1,3 +1,3 @@
1
1
  module Octoshark
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -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(ActiveRecord::Base.connection_pool).to eq(Octoshark.find_connection_pool(:default))
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)
@@ -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
- :current_connection_name, :disconnect!
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.5
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-21 00:00:00.000000000 Z
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