detector 0.8.0 → 0.8.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d21e960cc4220b3bf67a98d0ce5ef7f367710545173ff09cfcee580cc3895e64
4
- data.tar.gz: dba6d148d06ea37444017539b0bb23fd43cb96c9deeedf6235fc8e5cfe3999b7
3
+ metadata.gz: 160f91ff5337a5e65db122754c58acf167ea6c92a2628b6c4cae37dfbebbd2e9
4
+ data.tar.gz: '0691d5918ca772909057ebf059947f4f1b08cd8b5388f0cc7836842d980bf677'
5
5
  SHA512:
6
- metadata.gz: 19732b310f2f739e03c478103ebb1de34979145fd867d5beab4c82d8ef14c6405c7b4d9bac18849b79adba3dfc9e0e25c4dd0fcada4d6321e95a0822a9cc3efc
7
- data.tar.gz: 318344d8e1f23196e5fe2eef8435aec32729fe488d41b0277bcf567117df1f3dbe105269777310a51344aba2453565adc1506c014d1c972a33b02c8f32d1afe5
6
+ metadata.gz: a192f06a2497b21ac4475d2686615450eb800a888367a02eefb36dcf3ae5f7959712a49f4a33012aaa554fabd4d18390aac08e9671dddef38f6f4d8d97c9e561
7
+ data.tar.gz: f9426467573fae22f8fb192b342d376cc1fd04036079821c62c354f3dc0fe426417cdf34a8e3a18e7b09bda36ee2478176fcd1d70d2ac4c3642ea4b10aaa69e6
@@ -12,7 +12,8 @@ module Detector
12
12
  end
13
13
 
14
14
  def connection
15
- @conn ||= Mysql2::Client.new(
15
+ # Create a new connection each time without caching
16
+ Mysql2::Client.new(
16
17
  host: host,
17
18
  username: uri.user,
18
19
  password: uri.password,
@@ -12,7 +12,8 @@ module Detector
12
12
  end
13
13
 
14
14
  def connection
15
- @conn ||= PG::Connection.new(uri) rescue nil
15
+ # Create a new connection each time without caching
16
+ PG::Connection.new(uri) rescue nil
16
17
  end
17
18
 
18
19
  def version
@@ -13,12 +13,11 @@ module Detector
13
13
  end
14
14
 
15
15
  def connection
16
- return @conn if @conn
17
-
16
+ # Create a new connection each time without caching
18
17
  if uri.scheme == 'rediss'
19
- @conn = ::Redis.new(url: @url, port: uri.port, timeout: 5.0, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) rescue nil
18
+ ::Redis.new(url: @url, port: uri.port, timeout: 5.0, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) rescue nil
20
19
  else
21
- @conn = ::Redis.new(url: @url, timeout: 5.0) rescue nil
20
+ ::Redis.new(url: @url, timeout: 5.0) rescue nil
22
21
  end
23
22
  end
24
23
 
@@ -12,13 +12,12 @@ module Detector
12
12
  end
13
13
 
14
14
  def connection
15
- return @conn if @conn
16
-
15
+ # Create a new connection each time without caching
17
16
  begin
18
- @conn = Net::SMTP.new(host, port)
19
- @conn.open_timeout = 5
20
- @conn.start('detector.local', uri.user, uri.password, :login)
21
- @conn
17
+ conn = Net::SMTP.new(host, port)
18
+ conn.open_timeout = 5
19
+ conn.start('detector.local', uri.user, uri.password, :login)
20
+ conn
22
21
  rescue => e
23
22
  nil
24
23
  end
data/lib/detector/base.rb CHANGED
@@ -123,9 +123,24 @@ module Detector
123
123
  end
124
124
 
125
125
  def connection
126
+ # Default implementation returns nil
127
+ # Each addon should implement its own connection method
128
+ # that creates a new connection for each request
126
129
  nil
127
130
  end
128
131
 
132
+ def with_connection
133
+ conn = connection
134
+ return yield(nil) unless conn
135
+
136
+ begin
137
+ result = yield(conn)
138
+ return result
139
+ ensure
140
+ close
141
+ end
142
+ end
143
+
129
144
  def ping
130
145
  return nil unless valid?
131
146
  transport?
@@ -1,3 +1,3 @@
1
1
  module Detector
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: detector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel