advanced_connection 0.5.1 → 0.5.5

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: 62f7a17e7ed43268b606a797d1caf063a7315655
4
- data.tar.gz: e27f2b539440c06bb584c391823cffa513f07cb9
3
+ metadata.gz: 1b6cf3c3a0fdeacc8cde74431cd95e8ee086a785
4
+ data.tar.gz: df3db9850e19c1999b0e219ae8a5670b2c803750
5
5
  SHA512:
6
- metadata.gz: 42ed8c6c57cc86e27c18536b1b122c635599be016d0ec01252f652b1f42a47b571d3612bc695923b95e7e269bff88f3bc074f00ecfa93cf3d17571b1e1584e1d
7
- data.tar.gz: 7d54804ab6b0cd5c56c684d071608209f5a5cdc959ac121e8088b9eb0b145a4cbec7bbf7c02e4710ba48caf9eff5578bead5528d3982f2f8869ddc16b7d483c4
6
+ metadata.gz: 268715f2553969f63c9c6b54b17b5c3f1a046fb864f9df865185622b416973d3c749433d9bfab4d803b1e6fe7c984152756e8dfdccbaa5b391b09d6f65e9255b
7
+ data.tar.gz: b883bc28735538d6f7f095ac362363b357747028cb29c4aeac305c0d8d9aae5550392f715fca0491abb51ae0d4f39f8c6c9592fac44f5b20b135c4e4e064e316
data/.rubocop.yml ADDED
@@ -0,0 +1,205 @@
1
+ AllCops:
2
+ Include:
3
+ - Rakefile
4
+ Exclude:
5
+ - test.rb
6
+ - bin/**
7
+
8
+ SpecialGlobalVars:
9
+ Enabled: false
10
+
11
+ BlockComments:
12
+ Enabled: false
13
+
14
+ Encoding:
15
+ Enabled: false
16
+
17
+ RegexpLiteral:
18
+ Enabled: false
19
+
20
+ # dots at the end of lines are okay
21
+ DotPosition:
22
+ Enabled: false
23
+
24
+ CollectionMethods:
25
+ PreferredMethods:
26
+ map: 'collect'
27
+ map!: 'collect!'
28
+ reduce: 'inject'
29
+ detect: 'find'
30
+ find_all: 'select'
31
+
32
+ CaseIndentation:
33
+ IndentWhenRelativeTo: end
34
+ IndentOneStep: true
35
+
36
+ LineLength:
37
+ Enabled: false
38
+
39
+ # Personally, I prefer to outdent public/protected/private, as it makes
40
+ # it easier to see the different sections of code.
41
+ AccessModifierIndentation:
42
+ EnforcedStyle: outdent
43
+
44
+ EmptyLinesAroundAccessModifier:
45
+ Enabled: true
46
+
47
+ EndAlignment:
48
+ AlignWith: variable
49
+
50
+ SpaceInsideBrackets:
51
+ Enabled: false
52
+
53
+ Style/ClassAndModuleChildren:
54
+ Enabled: false
55
+
56
+ # Relaxed.Ruby.Style
57
+
58
+ Style/Alias:
59
+ Enabled: false
60
+ StyleGuide: http://relaxed.ruby.style/#stylealias
61
+
62
+ Style/BeginBlock:
63
+ Enabled: false
64
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
65
+
66
+ Style/BlockDelimiters:
67
+ Enabled: false
68
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
69
+
70
+ Style/Documentation:
71
+ Enabled: false
72
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
73
+
74
+ Style/DotPosition:
75
+ Enabled: false
76
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
77
+
78
+ Style/DoubleNegation:
79
+ Enabled: false
80
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
81
+
82
+ Style/EndBlock:
83
+ Enabled: false
84
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
85
+
86
+ Style/FormatString:
87
+ Enabled: false
88
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
89
+
90
+ Style/IfUnlessModifier:
91
+ Enabled: false
92
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
93
+
94
+ Style/Lambda:
95
+ Enabled: false
96
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
97
+
98
+ Style/ModuleFunction:
99
+ Enabled: false
100
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
101
+
102
+ Style/MultilineBlockChain:
103
+ Enabled: false
104
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
105
+
106
+ Style/NegatedIf:
107
+ Enabled: false
108
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
109
+
110
+ Style/NegatedWhile:
111
+ Enabled: false
112
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
113
+
114
+ Style/ParallelAssignment:
115
+ Enabled: false
116
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
117
+
118
+ Style/PercentLiteralDelimiters:
119
+ Enabled: false
120
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
121
+
122
+ Style/PerlBackrefs:
123
+ Enabled: false
124
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
125
+
126
+ Style/Semicolon:
127
+ Enabled: false
128
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
129
+
130
+ Style/SignalException:
131
+ Enabled: false
132
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
133
+
134
+ Style/SingleLineBlockParams:
135
+ Enabled: false
136
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
137
+
138
+ Style/SingleLineMethods:
139
+ Enabled: false
140
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
141
+
142
+ Style/SpaceBeforeBlockBraces:
143
+ Enabled: false
144
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
145
+
146
+ Style/SpaceInsideParens:
147
+ Enabled: false
148
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
149
+
150
+ Style/SpecialGlobalVars:
151
+ Enabled: false
152
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
153
+
154
+ Style/StringLiterals:
155
+ Enabled: false
156
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
157
+
158
+ Style/TrailingCommaInLiteral:
159
+ Enabled: false
160
+ StyleGuide: http://relaxed.ruby.style/#styletrailingcomma
161
+
162
+ Style/TrailingCommaInArguments:
163
+ Enabled: false
164
+ StyleGuide: http://relaxed.ruby.style/#styletrailingcomma
165
+
166
+ Style/WhileUntilModifier:
167
+ Enabled: false
168
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
169
+
170
+ Lint/AmbiguousRegexpLiteral:
171
+ Enabled: false
172
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
173
+
174
+ Lint/AssignmentInCondition:
175
+ Enabled: false
176
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
177
+
178
+ Metrics/AbcSize:
179
+ Enabled: false
180
+
181
+ Metrics/BlockNesting:
182
+ Enabled: false
183
+
184
+ Metrics/ClassLength:
185
+ Enabled: false
186
+
187
+ Metrics/ModuleLength:
188
+ Enabled: false
189
+
190
+ Metrics/CyclomaticComplexity:
191
+ Enabled: false
192
+
193
+ Metrics/LineLength:
194
+ Enabled: false
195
+
196
+ Metrics/MethodLength:
197
+ Enabled: false
198
+
199
+ Metrics/ParameterLists:
200
+ Enabled: false
201
+
202
+ Metrics/PerceivedComplexity:
203
+ Enabled: false
204
+
205
+
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- advanced_connection (0.5.1)
5
- activerecord (>= 4.1.0, < 5.0)
6
- activesupport (>= 4.1.0, < 5.0)
7
- rails (>= 4.1.0, < 5.0)
4
+ advanced_connection (0.5.5)
5
+ activerecord (~> 4.1)
6
+ activesupport (~> 4.1)
7
+ rails (~> 4.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -49,7 +49,6 @@ GEM
49
49
  charlock_holmes (0.7.3)
50
50
  coderay (1.1.1)
51
51
  concurrent-ruby (1.0.1)
52
- concurrent-ruby (1.0.1-java)
53
52
  copyright-header (1.0.15)
54
53
  github-linguist (~> 2.6)
55
54
  coveralls (0.8.13)
@@ -104,7 +103,6 @@ GEM
104
103
  nenv (0.3.0)
105
104
  nokogiri (1.6.7.2)
106
105
  mini_portile2 (~> 2.0.0.rc2)
107
- nokogiri (1.6.7.2-java)
108
106
  notiffany (0.0.8)
109
107
  nenv (~> 0.1)
110
108
  shellany (~> 0.0)
@@ -193,7 +191,6 @@ GEM
193
191
  tins (~> 1.0)
194
192
  thor (0.19.1)
195
193
  thread_safe (0.3.5)
196
- thread_safe (0.3.5-java)
197
194
  tins (1.6.0)
198
195
  tzinfo (1.2.2)
199
196
  thread_safe (~> 0.1)
@@ -205,14 +202,14 @@ PLATFORMS
205
202
 
206
203
  DEPENDENCIES
207
204
  advanced_connection!
208
- copyright-header (= 1.0.15)
209
- coveralls (~> 0.8)
210
- guard-rspec (~> 4.6)
211
- pg (~> 0.18)
212
- pry (~> 0.10)
213
- pry-nav (~> 0.2)
214
- rack (~> 1.6)
215
- rake (~> 10.5)
216
- rspec (~> 3.4)
217
- rspec-collection_matchers (~> 1.1)
218
- rspec-its (~> 1.2)
205
+ copyright-header (~> 1.0.15)
206
+ coveralls (~> 0.8.13)
207
+ guard-rspec (~> 4.6.4)
208
+ pg (~> 0.18.4)
209
+ pry (~> 0.10.3)
210
+ pry-nav (~> 0.2.4)
211
+ rack (~> 1.6.4)
212
+ rake (~> 10.5.0)
213
+ rspec (~> 3.4.0)
214
+ rspec-collection_matchers (~> 1.1.2)
215
+ rspec-its (~> 1.2.0)
@@ -24,26 +24,26 @@ Gem::Specification.new do |spec|
24
24
  # :jruby => '~> 1.7',
25
25
  # }
26
26
 
27
- spec.add_runtime_dependency "rails", ">= 4.1.0", "< 5.0"
28
- spec.add_runtime_dependency "activerecord", ">= 4.1.0", "< 5.0"
29
- spec.add_runtime_dependency "activesupport", ">= 4.1.0", "< 5.0"
27
+ spec.add_runtime_dependency "rails", "~> 4.1"
28
+ spec.add_runtime_dependency "activerecord", "~> 4.1"
29
+ spec.add_runtime_dependency "activesupport", "~> 4.1"
30
30
 
31
- spec.add_development_dependency "rake", '~> 10.5'
32
- spec.add_development_dependency "rack", '~> 1.6'
33
- spec.add_development_dependency "rspec", '~> 3.4'
34
- spec.add_development_dependency "rspec-its", '~> 1.2'
35
- spec.add_development_dependency "rspec-collection_matchers", '~> 1.1'
31
+ spec.add_development_dependency "rake", '~> 10.5.0'
32
+ spec.add_development_dependency "rack", '~> 1.6.4'
33
+ spec.add_development_dependency "rspec", '~> 3.4.0'
34
+ spec.add_development_dependency "rspec-its", '~> 1.2.0'
35
+ spec.add_development_dependency "rspec-collection_matchers", '~> 1.1.2'
36
36
 
37
37
  # optional dependencies
38
38
  if RUBY_ENGINE == 'jruby'
39
- spec.add_development_dependency "activerecord-jdbcpostgresql-adapter", "~> 1.3"
39
+ spec.add_development_dependency "activerecord-jdbcpostgresql-adapter", "~> 1.3.19"
40
40
  else
41
- spec.add_development_dependency "pg", "~> 0.18"
42
- spec.add_development_dependency "pry", '~> 0.10'
43
- spec.add_development_dependency "pry-nav", '~> 0.2'
41
+ spec.add_development_dependency "pg", "~> 0.18.4"
42
+ spec.add_development_dependency "pry", '~> 0.10.3'
43
+ spec.add_development_dependency "pry-nav", '~> 0.2.4'
44
44
  end
45
45
 
46
- spec.add_development_dependency "guard-rspec", '~> 4.6'
47
- spec.add_development_dependency "coveralls", '~> 0.8'
48
- spec.add_development_dependency 'copyright-header', '= 1.0.15'
46
+ spec.add_development_dependency "guard-rspec", '~> 4.6.4'
47
+ spec.add_development_dependency "coveralls", '~> 0.8.13'
48
+ spec.add_development_dependency 'copyright-header', '~> 1.0.15'
49
49
  end
@@ -42,9 +42,7 @@ module AdvancedConnection
42
42
 
43
43
  def configure(overwrite = true)
44
44
  return unless overwrite
45
- (yield config).tap {
46
- config.loaded!
47
- }
45
+ (yield config).tap { config.loaded! }
48
46
  end
49
47
 
50
48
  def config
@@ -62,4 +60,4 @@ module AdvancedConnection
62
60
  end
63
61
 
64
62
  require 'advanced_connection/railtie' if defined?(Rails)
65
- end
63
+ end
@@ -51,9 +51,9 @@ module AdvancedConnection
51
51
 
52
52
  ActiveRecord::Base.instance_exec do
53
53
  if AdvancedConnection.enable_without_connection
54
- extend ActiveRecordExt::WithoutConnection unless AdvancedConnection::enable_statement_pooling
54
+ extend ActiveRecordExt::WithoutConnection unless AdvancedConnection.enable_statement_pooling
55
55
  end
56
56
  end
57
57
  end
58
58
  end
59
- end
59
+ end
@@ -45,4 +45,4 @@ module AdvancedConnection::ActiveRecordExt
45
45
  (Time.now - @instantiated_at).to_f
46
46
  end
47
47
  end
48
- end
48
+ end
@@ -28,43 +28,39 @@ module AdvancedConnection::ActiveRecordExt
28
28
 
29
29
  module ExecuteWrapper
30
30
  def __wrap_adapter_exec_methods(*methods)
31
- Array(methods).flatten.collect(&:to_sym).each { |exec_method|
31
+ Array(methods).flatten.collect(&:to_sym).each do |exec_method|
32
32
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
33
33
  def #{exec_method}_with_callback(sql, *args, &block)
34
34
  if Thread.current[:without_callbacks] || sql =~ /^BEGIN/i || transaction_open? || pool.nil?
35
35
  #{exec_method}_without_callback(sql, *args, &block)
36
36
  else
37
37
  run_callbacks(:statement_pooling_connection_checkin) do
38
- $stderr.puts "#{Thread.current.object_id} executing sql -> \#{sql.inspect}"
39
38
  #{exec_method}_without_callback(sql, *args, &block).tap {
40
- $stderr.puts "#{Thread.current.object_id} Releasing connection..."
41
39
  reset!
42
40
  pool.release_connection
43
- $stderr.puts "#{Thread.current.object_id} Connection Released..."
44
41
  }
45
42
  end
46
43
  end
47
44
  end
48
45
  EOS
49
46
  alias_method_chain exec_method, :callback
50
- }
47
+ end
51
48
  end
52
49
  alias_method :__wrap_adapter_exec_method, :__wrap_adapter_exec_methods
53
50
 
54
51
  def __wrap_without_callbacks(*methods)
55
- Array(methods).flatten.collect(&:to_sym).each { |m|
56
- target, punctuation = m.to_s.sub(/([?!=])$/, ''), $1
52
+ Array(methods).flatten.collect(&:to_sym).each do |exec_method|
53
+ target, punctuation = exec_method.to_s.sub(/([?!=])$/, ''), $1
57
54
  class_eval(<<-EOS, __FILE__, __LINE__ + 1)
58
55
  def #{target}_with_no_callbacks#{punctuation}(*args, &block)
59
- # $stderr.puts "setting without_callbacks to true"
60
56
  Thread.current[:without_callbacks] = true
61
57
  #{target}_without_no_callbacks#{punctuation}(*args, &block)
62
58
  ensure
63
59
  Thread.current[:without_callbacks] = nil
64
60
  end
65
61
  EOS
66
- alias_method_chain m, :no_callbacks
67
- }
62
+ alias_method_chain exec_method, :no_callbacks
63
+ end
68
64
  end
69
65
  alias_method :__wrap_without_callback, :__wrap_without_callbacks
70
66
  end
@@ -78,7 +74,7 @@ module AdvancedConnection::ActiveRecordExt
78
74
  set_callback :statement_pooling_connection_checkin, :before, :before_connection_checkin
79
75
  set_callback :statement_pooling_connection_checkin, :after, :after_connection_checkin
80
76
 
81
- DEFAULT_EXEC_METHODS = [ :execute, :exec_no_cache, :query ]
77
+ DEFAULT_EXEC_METHODS = [ :execute, :exec_no_cache, :query ].freeze
82
78
  JDBC_EXEC_METHODS = %w[
83
79
  execute
84
80
  exec_query
@@ -90,21 +86,21 @@ module AdvancedConnection::ActiveRecordExt
90
86
  ].collect(&:to_sym)
91
87
 
92
88
  if RUBY_ENGINE == 'jruby'
93
- JDBC_EXEC_METHODS.each { |m| __wrap_adapter_exec_methods m }
89
+ JDBC_EXEC_METHODS.each { |exec_method| __wrap_adapter_exec_methods exec_method }
94
90
  else
95
- DEFAULT_EXEC_METHODS.each { |m| __wrap_adapter_exec_methods m }
91
+ DEFAULT_EXEC_METHODS.each { |exec_method| __wrap_adapter_exec_methods exec_method }
96
92
  end
97
93
 
98
- [ :active?, :reset!, :disconnect!, :reconnect! ].each { |m|
99
- __wrap_without_callbacks m
94
+ [ :active?, :reset!, :disconnect!, :reconnect! ].each { |exec_method|
95
+ __wrap_without_callbacks exec_method
100
96
  }
101
97
  end
102
98
 
103
- def around_connection_checkin(&block)
99
+ def around_connection_checkin
104
100
  callbacks = AdvancedConnection.callbacks.statement_pooling
105
- if callbacks.around.respond_to? :call
106
- callbacks.around.call() { block.call }
107
- end
101
+ callbacks.around.call do
102
+ yield
103
+ end if callbacks.around.respond_to? :call
108
104
  end
109
105
 
110
106
  def before_connection_checkin
@@ -118,4 +114,4 @@ module AdvancedConnection::ActiveRecordExt
118
114
  end
119
115
  end
120
116
  end
121
- end
117
+ end
@@ -35,4 +35,4 @@ module AdvancedConnection
35
35
  end
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -29,7 +29,7 @@ module AdvancedConnection::ActiveRecordExt
29
29
  alias_method_chain :checkin, :last_checked_in
30
30
 
31
31
  class IdleManager
32
- attr_reader :pool, :interval, :thread
32
+ attr_reader :thread
33
33
 
34
34
  def initialize(pool, interval)
35
35
  @pool = pool
@@ -38,22 +38,22 @@ module AdvancedConnection::ActiveRecordExt
38
38
  end
39
39
 
40
40
  def run
41
- return unless interval > 0
41
+ return unless @interval > 0
42
42
 
43
- @thread ||= Thread.new(pool, interval) { |_pool, _interval|
44
- _pool.send(:idle_info, "starting idle manager; running every #{_interval} seconds")
43
+ @thread ||= Thread.new(@pool, @interval) { |pool, interval|
44
+ pool.send(:idle_info, "starting idle manager; running every #{interval} seconds")
45
45
 
46
46
  loop do
47
- sleep _interval
47
+ sleep interval
48
48
 
49
49
  begin
50
50
  start = Time.now
51
- _pool.send(:idle_info, "beginning idle connection cleanup")
52
- _pool.remove_idle_connections
53
- _pool.send(:idle_info, "beginning idle connection warmup")
54
- _pool.create_idle_connections
51
+ pool.send(:idle_info, "beginning idle connection cleanup")
52
+ pool.remove_idle_connections
53
+ pool.send(:idle_info, "beginning idle connection warmup")
54
+ pool.create_idle_connections
55
55
  finish = (Time.now - start).round(6)
56
- _pool.send(:idle_info, "finished idle connection tasks in #{finish} seconds.; next run in #{pool.max_idle_time} seconds")
56
+ pool.send(:idle_info, "finished idle connection tasks in #{finish} seconds; next run in #{pool.max_idle_time} seconds")
57
57
  rescue => e
58
58
  Rails.logger.error "#{e.class.name}: #{e.message}"
59
59
  e.backtrace.each { |line| Rails.logger.error line }
@@ -67,21 +67,21 @@ module AdvancedConnection::ActiveRecordExt
67
67
  def initialize_with_advanced_connection(spec)
68
68
  initialize_without_advanced_connection(spec)
69
69
 
70
- @available = case queue_type
70
+ @available = case queue_type
71
71
  when :prefer_older then Queues::OldAgeBiased.new
72
72
  when :prefer_younger then Queues::YoungAgeBiased.new
73
73
  when :lifo, :stack then Queues::Stack.new
74
- else
75
- Rails.logger.warn "Unknown queue_type #{queue_type.inspect} - using standard FIFO instead"
76
- Queues::FIFO.new
74
+ else
75
+ Rails.logger.warn "Unknown queue_type #{queue_type.inspect} - using standard FIFO instead"
76
+ Queues::FIFO.new
77
77
  end
78
78
 
79
- @idle_manager = IdleManager.new(self, idle_check_interval).tap { |m| m.run }
79
+ @idle_manager = IdleManager.new(self, idle_check_interval).tap(&:run)
80
80
  end
81
81
 
82
82
  def queue_type
83
83
  @queue_type ||= spec.config.fetch(:queue_type,
84
- AdvancedConnection.connection_pool_queue_type).to_s.downcase.to_sym
84
+ AdvancedConnection.connection_pool_queue_type).to_s.downcase.to_sym
85
85
  end
86
86
 
87
87
  def warmup_connection_count
@@ -143,7 +143,7 @@ module AdvancedConnection::ActiveRecordExt
143
143
  def idle_connections
144
144
  available_connections.select do |conn|
145
145
  (Time.now - conn.last_checked_in).to_f > max_idle_time
146
- end.sort { |a,b|
146
+ end.sort { |a, b|
147
147
  case queue_type
148
148
  when :prefer_younger then
149
149
  # when prefering younger, we sort oldest->youngest
@@ -175,9 +175,12 @@ module AdvancedConnection::ActiveRecordExt
175
175
  end
176
176
  total = active + available
177
177
 
178
- ActiveSupport::OrderedOptions.new.merge({
179
- total: total, idle: idle, active: active, available: available,
180
- })
178
+ ActiveSupport::OrderedOptions.new.merge(
179
+ total: total,
180
+ idle: idle,
181
+ active: active,
182
+ available: available,
183
+ )
181
184
  end
182
185
 
183
186
  def warmup_connections(count = nil)
@@ -268,4 +271,4 @@ module AdvancedConnection::ActiveRecordExt
268
271
  end
269
272
  end
270
273
  end
271
- end
274
+ end
@@ -57,4 +57,4 @@ module AdvancedConnection::ActiveRecordExt
57
57
  end
58
58
  end
59
59
  end
60
- end
60
+ end
@@ -39,4 +39,4 @@ module AdvancedConnection::ActiveRecordExt
39
39
  end
40
40
  end
41
41
  end
42
- end
42
+ end
@@ -39,55 +39,53 @@ module AdvancedConnection::ActiveRecordExt
39
39
 
40
40
  if AdvancedConnection.callbacks.without_connection.present?
41
41
  run_callbacks(:without_connection) do
42
- __without_connection() { yield }
42
+ __without_connection do
43
+ yield
44
+ end
43
45
  end
44
46
  else
45
- __without_connection() { yield }
47
+ __without_connection do
48
+ yield
49
+ end
46
50
  end
47
51
  end
48
52
 
49
53
  private
50
54
 
51
55
  def __without_connection
56
+ # return the connection to the pool for the duration of `yield`
57
+ release_connection if active_connection?
58
+ raise Error::UnableToReleaseConnection if active_connection?
59
+ yield
60
+ ensure
61
+ tries = 3
52
62
  begin
53
- # return the connection to the pool for the duration of `yield`
54
- release_connection if active_connection?
55
- raise Error::UnableToReleaseConnection if active_connection?
56
- yield
57
- ensure
58
- tries = 3
59
- begin
60
- # attempt to retrieve another connection
61
- retrieve_connection
62
- rescue ActiveRecord::ConnectionTimeoutError
63
- Rails.logger.info "Failed to acquire a connection (#{Thread.current.object_id}) trying #{tries > 1 ? "#{tries} more times" : 'once more'}"
64
- retry unless (tries -= 1) < 0
65
- Rails.logger.info "Giving up on trying to acquire another connection"
66
- raise
67
- end
63
+ # attempt to retrieve another connection
64
+ retrieve_connection
65
+ rescue ActiveRecord::ConnectionTimeoutError
66
+ Rails.logger.info "Failed to acquire a connection (#{Thread.current.object_id}) trying #{tries > 1 ? "#{tries} more times" : 'once more'}"
67
+ retry unless (tries -= 1) < 0
68
+ Rails.logger.info "Giving up on trying to acquire another connection"
69
+ raise
68
70
  end
69
71
  end
70
72
 
71
- def around_without_connection(&block)
73
+ def around_without_connection
72
74
  callbacks = AdvancedConnection.callbacks.without_connection
73
- if callbacks.around.respond_to? :call
74
- callbacks.around.call() { block.call }
75
- end
75
+ callbacks.around.call do
76
+ yield
77
+ end if callbacks.around.respond_to? :call
76
78
  end
77
79
 
78
80
  def before_without_connection
79
81
  callbacks = AdvancedConnection.callbacks.without_connection
80
- if callbacks.before.respond_to? :call
81
- callbacks.before.call
82
- end
82
+ callbacks.before.call if callbacks.before.respond_to? :call
83
83
  end
84
84
 
85
85
  def after_without_connection
86
86
  callbacks = AdvancedConnection.callbacks.without_connection
87
- if callbacks.after.respond_to? :call
88
- callbacks.after.call
89
- end
87
+ callbacks.after.call if callbacks.after.respond_to? :call
90
88
  end
91
89
  end
92
90
  end
93
- end
91
+ end
@@ -29,24 +29,24 @@ module AdvancedConnection
29
29
  :fifo, :lifo, :stack, :prefer_younger, :prefer_older
30
30
  ].freeze unless defined? VALID_QUEUE_TYPES
31
31
 
32
- CALLBACK_TYPES = ActiveSupport::OrderedOptions.new.merge({
32
+ CALLBACK_TYPES = ActiveSupport::OrderedOptions.new.merge(
33
33
  before: nil,
34
34
  around: nil,
35
35
  after: nil
36
- }).freeze unless defined? CALLBACK_TYPES
37
-
38
- DEFAULT_CONFIG = ActiveSupport::OrderedOptions.new.merge({
39
- :enable_without_connection => false,
40
- :enable_statement_pooling => false,
41
- :enable_idle_connection_manager => false,
42
- :connection_pool_queue_type => :fifo,
43
- :warmup_connections => false,
44
- :min_idle_connections => 0,
45
- :max_idle_connections => ::Float::INFINITY,
46
- :max_idle_time => 0,
47
- :idle_check_interval => 0,
48
- :callbacks => ActiveSupport::OrderedOptions.new
49
- }).freeze unless defined? DEFAULT_CONFIG
36
+ ).freeze unless defined? CALLBACK_TYPES
37
+
38
+ DEFAULT_CONFIG = ActiveSupport::OrderedOptions.new.merge(
39
+ enable_without_connection: false,
40
+ enable_statement_pooling: false,
41
+ enable_idle_connection_manager: false,
42
+ connection_pool_queue_type: :fifo,
43
+ warmup_connections: false,
44
+ min_idle_connections: 0,
45
+ max_idle_connections: ::Float::INFINITY,
46
+ max_idle_time: 0,
47
+ idle_check_interval: 0,
48
+ callbacks: ActiveSupport::OrderedOptions.new
49
+ ).freeze unless defined? DEFAULT_CONFIG
50
50
 
51
51
  class << self
52
52
  def method_missing(method, *args, &block)
@@ -55,7 +55,7 @@ module AdvancedConnection
55
55
  end
56
56
 
57
57
  def respond_to_missing?(method, include_private = false)
58
- instance.respond_to?(method) || super
58
+ instance.respond_to?(method, include_private) || super
59
59
  end
60
60
 
61
61
  def include?(key)
@@ -93,6 +93,9 @@ module AdvancedConnection
93
93
 
94
94
  add_callbacks :without_connection, :statement_pooling
95
95
 
96
+ attr_reader :loaded
97
+ alias_method :loaded?, :loaded
98
+
96
99
  def initialize
97
100
  @loaded = false
98
101
  @config = DEFAULT_CONFIG.deep_dup
@@ -102,10 +105,6 @@ module AdvancedConnection
102
105
  @loaded = true
103
106
  end
104
107
 
105
- def loaded?
106
- @loaded
107
- end
108
-
109
108
  def [](key)
110
109
  @config[key.to_sym]
111
110
  end
@@ -161,16 +160,12 @@ module AdvancedConnection
161
160
  end
162
161
 
163
162
  def warmup_connections=(value)
164
- unless value.nil? || value === false || value.is_a?(Fixnum) || value =~ /^\d+$/
163
+ unless !!value || value.is_a?(Fixnum) || value =~ /^\d+$/
165
164
  fail Error::ConfigError, 'Expected warmup_connections to be nil, false ' \
166
165
  "or a valid positive integer, but found `#{value.inspect}`"
167
166
  end
168
167
 
169
- if value.to_s =~ /^\d+$/
170
- @config[:warmup_connections] = value.to_i
171
- else
172
- @config[:warmup_connections] = false
173
- end
168
+ @config[:warmup_connections] = value.to_s =~ /^\d+$/ ? value.to_i : false
174
169
  end
175
170
 
176
171
  def min_idle_connections
@@ -196,8 +191,8 @@ module AdvancedConnection
196
191
  end
197
192
  @config[:max_idle_connections] = begin
198
193
  value.to_i
199
- rescue FloatDomainError => e
200
- raise unless e.message =~ /infinity/i
194
+ rescue FloatDomainError
195
+ raise unless $!.message =~ /infinity/i
201
196
  ::Float::INFINITY
202
197
  end
203
198
  end
@@ -244,4 +239,4 @@ module AdvancedConnection
244
239
  @config[:connection_pool_queue_type] = value
245
240
  end
246
241
  end
247
- end
242
+ end
@@ -37,4 +37,4 @@ module AdvancedConnection
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
@@ -22,7 +22,7 @@
22
22
  module AdvancedConnection
23
23
  MAJOR = 0
24
24
  MINOR = 5
25
- PATCH = 1
25
+ PATCH = 5
26
26
 
27
27
  VERSION = "%d.%d.%d" % [ MAJOR, MINOR, PATCH ]
28
28
  GEM_VERSION = Gem::Version.new(VERSION)
@@ -139,4 +139,4 @@ AdvancedConnection.configure do |config|
139
139
  # end
140
140
  # }
141
141
  # }
142
- end
142
+ end
metadata CHANGED
@@ -1,227 +1,209 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advanced_connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl P. Corliss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-28 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.1.0
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '5.0'
19
+ version: '4.1'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 4.1.0
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '5.0'
26
+ version: '4.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: activerecord
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 4.1.0
40
- - - "<"
31
+ - - "~>"
41
32
  - !ruby/object:Gem::Version
42
- version: '5.0'
33
+ version: '4.1'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: 4.1.0
50
- - - "<"
38
+ - - "~>"
51
39
  - !ruby/object:Gem::Version
52
- version: '5.0'
40
+ version: '4.1'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: activesupport
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: 4.1.0
60
- - - "<"
45
+ - - "~>"
61
46
  - !ruby/object:Gem::Version
62
- version: '5.0'
47
+ version: '4.1'
63
48
  type: :runtime
64
49
  prerelease: false
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 4.1.0
70
- - - "<"
52
+ - - "~>"
71
53
  - !ruby/object:Gem::Version
72
- version: '5.0'
54
+ version: '4.1'
73
55
  - !ruby/object:Gem::Dependency
74
56
  name: rake
75
57
  requirement: !ruby/object:Gem::Requirement
76
58
  requirements:
77
59
  - - "~>"
78
60
  - !ruby/object:Gem::Version
79
- version: '10.5'
61
+ version: 10.5.0
80
62
  type: :development
81
63
  prerelease: false
82
64
  version_requirements: !ruby/object:Gem::Requirement
83
65
  requirements:
84
66
  - - "~>"
85
67
  - !ruby/object:Gem::Version
86
- version: '10.5'
68
+ version: 10.5.0
87
69
  - !ruby/object:Gem::Dependency
88
70
  name: rack
89
71
  requirement: !ruby/object:Gem::Requirement
90
72
  requirements:
91
73
  - - "~>"
92
74
  - !ruby/object:Gem::Version
93
- version: '1.6'
75
+ version: 1.6.4
94
76
  type: :development
95
77
  prerelease: false
96
78
  version_requirements: !ruby/object:Gem::Requirement
97
79
  requirements:
98
80
  - - "~>"
99
81
  - !ruby/object:Gem::Version
100
- version: '1.6'
82
+ version: 1.6.4
101
83
  - !ruby/object:Gem::Dependency
102
84
  name: rspec
103
85
  requirement: !ruby/object:Gem::Requirement
104
86
  requirements:
105
87
  - - "~>"
106
88
  - !ruby/object:Gem::Version
107
- version: '3.4'
89
+ version: 3.4.0
108
90
  type: :development
109
91
  prerelease: false
110
92
  version_requirements: !ruby/object:Gem::Requirement
111
93
  requirements:
112
94
  - - "~>"
113
95
  - !ruby/object:Gem::Version
114
- version: '3.4'
96
+ version: 3.4.0
115
97
  - !ruby/object:Gem::Dependency
116
98
  name: rspec-its
117
99
  requirement: !ruby/object:Gem::Requirement
118
100
  requirements:
119
101
  - - "~>"
120
102
  - !ruby/object:Gem::Version
121
- version: '1.2'
103
+ version: 1.2.0
122
104
  type: :development
123
105
  prerelease: false
124
106
  version_requirements: !ruby/object:Gem::Requirement
125
107
  requirements:
126
108
  - - "~>"
127
109
  - !ruby/object:Gem::Version
128
- version: '1.2'
110
+ version: 1.2.0
129
111
  - !ruby/object:Gem::Dependency
130
112
  name: rspec-collection_matchers
131
113
  requirement: !ruby/object:Gem::Requirement
132
114
  requirements:
133
115
  - - "~>"
134
116
  - !ruby/object:Gem::Version
135
- version: '1.1'
117
+ version: 1.1.2
136
118
  type: :development
137
119
  prerelease: false
138
120
  version_requirements: !ruby/object:Gem::Requirement
139
121
  requirements:
140
122
  - - "~>"
141
123
  - !ruby/object:Gem::Version
142
- version: '1.1'
124
+ version: 1.1.2
143
125
  - !ruby/object:Gem::Dependency
144
126
  name: pg
145
127
  requirement: !ruby/object:Gem::Requirement
146
128
  requirements:
147
129
  - - "~>"
148
130
  - !ruby/object:Gem::Version
149
- version: '0.18'
131
+ version: 0.18.4
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
135
  requirements:
154
136
  - - "~>"
155
137
  - !ruby/object:Gem::Version
156
- version: '0.18'
138
+ version: 0.18.4
157
139
  - !ruby/object:Gem::Dependency
158
140
  name: pry
159
141
  requirement: !ruby/object:Gem::Requirement
160
142
  requirements:
161
143
  - - "~>"
162
144
  - !ruby/object:Gem::Version
163
- version: '0.10'
145
+ version: 0.10.3
164
146
  type: :development
165
147
  prerelease: false
166
148
  version_requirements: !ruby/object:Gem::Requirement
167
149
  requirements:
168
150
  - - "~>"
169
151
  - !ruby/object:Gem::Version
170
- version: '0.10'
152
+ version: 0.10.3
171
153
  - !ruby/object:Gem::Dependency
172
154
  name: pry-nav
173
155
  requirement: !ruby/object:Gem::Requirement
174
156
  requirements:
175
157
  - - "~>"
176
158
  - !ruby/object:Gem::Version
177
- version: '0.2'
159
+ version: 0.2.4
178
160
  type: :development
179
161
  prerelease: false
180
162
  version_requirements: !ruby/object:Gem::Requirement
181
163
  requirements:
182
164
  - - "~>"
183
165
  - !ruby/object:Gem::Version
184
- version: '0.2'
166
+ version: 0.2.4
185
167
  - !ruby/object:Gem::Dependency
186
168
  name: guard-rspec
187
169
  requirement: !ruby/object:Gem::Requirement
188
170
  requirements:
189
171
  - - "~>"
190
172
  - !ruby/object:Gem::Version
191
- version: '4.6'
173
+ version: 4.6.4
192
174
  type: :development
193
175
  prerelease: false
194
176
  version_requirements: !ruby/object:Gem::Requirement
195
177
  requirements:
196
178
  - - "~>"
197
179
  - !ruby/object:Gem::Version
198
- version: '4.6'
180
+ version: 4.6.4
199
181
  - !ruby/object:Gem::Dependency
200
182
  name: coveralls
201
183
  requirement: !ruby/object:Gem::Requirement
202
184
  requirements:
203
185
  - - "~>"
204
186
  - !ruby/object:Gem::Version
205
- version: '0.8'
187
+ version: 0.8.13
206
188
  type: :development
207
189
  prerelease: false
208
190
  version_requirements: !ruby/object:Gem::Requirement
209
191
  requirements:
210
192
  - - "~>"
211
193
  - !ruby/object:Gem::Version
212
- version: '0.8'
194
+ version: 0.8.13
213
195
  - !ruby/object:Gem::Dependency
214
196
  name: copyright-header
215
197
  requirement: !ruby/object:Gem::Requirement
216
198
  requirements:
217
- - - '='
199
+ - - "~>"
218
200
  - !ruby/object:Gem::Version
219
201
  version: 1.0.15
220
202
  type: :development
221
203
  prerelease: false
222
204
  version_requirements: !ruby/object:Gem::Requirement
223
205
  requirements:
224
- - - '='
206
+ - - "~>"
225
207
  - !ruby/object:Gem::Version
226
208
  version: 1.0.15
227
209
  description: Adds idle connection management, statement pooling, and other advanced
@@ -235,6 +217,7 @@ files:
235
217
  - ".document"
236
218
  - ".gitignore"
237
219
  - ".rspec"
220
+ - ".rubocop.yml"
238
221
  - ".travis.yml"
239
222
  - Gemfile
240
223
  - Gemfile.lock
@@ -263,7 +246,6 @@ files:
263
246
  - lib/generators/advanced_connection/install/USAGE
264
247
  - lib/generators/advanced_connection/install/install_generator.rb
265
248
  - lib/generators/advanced_connection/install/templates/advanced_connection.rb
266
- - lib/tasks/advanced_connection_tasks.rake
267
249
  - spec/config/database.yml
268
250
  - spec/config/database.yml.erb
269
251
  - spec/dummy/.gitignore
@@ -1,25 +0,0 @@
1
- #
2
- # Copyright (C) 2016 Finalsite, LLC
3
- # Copyright (C) 2016 Carl P. Corliss <carl.corliss@finalsite.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- # this software and associated documentation files (the "Software"), to deal in
7
- # the Software without restriction, including without limitation the rights to
8
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- # the Software, and to permit persons to whom the Software is furnished to do so,
10
- # subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
- #
22
- # desc "Explaining what the task does"
23
- # task :advanced_connection do
24
- # # Task goes here
25
- # end