1
0
Fork 0
mirror of https://github.com/mperham/connection_pool synced 2023-03-27 23:22:21 -04:00

integrate standard

This commit is contained in:
Mike Perham 2022-08-31 10:20:44 -07:00
parent d2ff737ab6
commit 2c927744bb
No known key found for this signature in database
8 changed files with 14 additions and 10 deletions

3
.standard.yml Normal file
View file

@ -0,0 +1,3 @@
ruby_version: 2.5.0
fix: true
parallel: true

View file

@ -1,3 +1,4 @@
source "https://rubygems.org" source "https://rubygems.org"
gemspec(development_group: :runtime) gemspec(development_group: :runtime)
gem "standard", group: [:development, :test]

View file

@ -1,6 +1,6 @@
require "bundler/gem_tasks" require "bundler/gem_tasks"
require "standard/rake"
require "rake/testtask" require "rake/testtask"
Rake::TestTask.new Rake::TestTask.new
task default: :test task default: [:"standard:fix", :test]

View file

@ -12,7 +12,6 @@ Gem::Specification.new do |s|
s.files = ["Changes.md", "LICENSE", "README.md", "connection_pool.gemspec", s.files = ["Changes.md", "LICENSE", "README.md", "connection_pool.gemspec",
"lib/connection_pool.rb", "lib/connection_pool/timed_stack.rb", "lib/connection_pool.rb", "lib/connection_pool/timed_stack.rb",
"lib/connection_pool/version.rb", "lib/connection_pool/wrapper.rb"] "lib/connection_pool/version.rb", "lib/connection_pool/wrapper.rb"]
s.test_files = ["test/helper.rb", "test/test_connection_pool.rb", "test/test_connection_pool_timed_stack.rb"]
s.executables = [] s.executables = []
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.license = "MIT" s.license = "MIT"

View file

@ -3,7 +3,9 @@ require_relative "connection_pool/version"
class ConnectionPool class ConnectionPool
class Error < ::RuntimeError; end class Error < ::RuntimeError; end
class PoolShuttingDownError < ::ConnectionPool::Error; end class PoolShuttingDownError < ::ConnectionPool::Error; end
class TimeoutError < ::Timeout::Error; end class TimeoutError < ::Timeout::Error; end
end end
@ -67,7 +69,7 @@ class ConnectionPool
end end
end end
end end
alias then with alias_method :then, :with
def checkout(options = {}) def checkout(options = {})
if ::Thread.current[@key] if ::Thread.current[@key]

View file

@ -49,7 +49,7 @@ class ConnectionPool::TimedStack
@resource.broadcast @resource.broadcast
end end
end end
alias << push alias_method :<<, :push
## ##
# Retrieves a connection from the stack. If a connection is available it is # Retrieves a connection from the stack. If a connection is available it is
@ -87,7 +87,7 @@ class ConnectionPool::TimedStack
# +:reload+ is +true+. # +:reload+ is +true+.
def shutdown(reload: false, &block) def shutdown(reload: false, &block)
raise ArgumentError, "shutdown must receive a block" unless block_given? raise ArgumentError, "shutdown must receive a block" unless block
@mutex.synchronize do @mutex.synchronize do
@shutdown_block = block @shutdown_block = block

View file

@ -30,7 +30,6 @@ class ConnectionPool
METHODS.include?(id) || with { |c| c.respond_to?(id, *args) } METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
end end
# rubocop:disable Style/MethodMissingSuper
# rubocop:disable Style/MissingRespondToMissing # rubocop:disable Style/MissingRespondToMissing
if ::RUBY_VERSION >= "3.0.0" if ::RUBY_VERSION >= "3.0.0"
def method_missing(name, *args, **kwargs, &block) def method_missing(name, *args, **kwargs, &block)

View file

@ -339,7 +339,7 @@ class TestConnectionPool < Minitest::Test
assert_equal 5, pool.do_something_with_block { 3 } assert_equal 5, pool.do_something_with_block { 3 }
assert_equal 6, pool.with { |net| net.fast } assert_equal 6, pool.with { |net| net.fast }
assert_equal 8, pool.do_something(increment: 2) assert_equal 8, pool.do_something(increment: 2)
assert_equal 10, pool.do_something_with_positional_hash({ increment: 2, symbol_key: 3, "string_key" => 4 }) assert_equal 10, pool.do_something_with_positional_hash({:increment => 2, :symbol_key => 3, "string_key" => 4})
end end
def test_passthru_respond_to def test_passthru_respond_to