From 2c927744bb4ef77cc61c4e298d6328a959533e17 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Wed, 31 Aug 2022 10:20:44 -0700 Subject: [PATCH] integrate standard --- .standard.yml | 3 +++ Gemfile | 1 + Rakefile | 4 ++-- connection_pool.gemspec | 5 ++--- lib/connection_pool.rb | 4 +++- lib/connection_pool/timed_stack.rb | 4 ++-- lib/connection_pool/wrapper.rb | 1 - test/test_connection_pool.rb | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 .standard.yml diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..c45c691 --- /dev/null +++ b/.standard.yml @@ -0,0 +1,3 @@ +ruby_version: 2.5.0 +fix: true +parallel: true diff --git a/Gemfile b/Gemfile index 85b5d55..af8051a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ source "https://rubygems.org" gemspec(development_group: :runtime) +gem "standard", group: [:development, :test] diff --git a/Rakefile b/Rakefile index 715af3d..9eb08fc 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ require "bundler/gem_tasks" - +require "standard/rake" require "rake/testtask" Rake::TestTask.new -task default: :test +task default: [:"standard:fix", :test] diff --git a/connection_pool.gemspec b/connection_pool.gemspec index fcb238d..e48aa23 100644 --- a/connection_pool.gemspec +++ b/connection_pool.gemspec @@ -10,9 +10,8 @@ Gem::Specification.new do |s| s.description = s.summary = "Generic connection pool for Ruby" s.files = ["Changes.md", "LICENSE", "README.md", "connection_pool.gemspec", - "lib/connection_pool.rb", "lib/connection_pool/timed_stack.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"] + "lib/connection_pool.rb", "lib/connection_pool/timed_stack.rb", + "lib/connection_pool/version.rb", "lib/connection_pool/wrapper.rb"] s.executables = [] s.require_paths = ["lib"] s.license = "MIT" diff --git a/lib/connection_pool.rb b/lib/connection_pool.rb index 731902a..1deaf67 100644 --- a/lib/connection_pool.rb +++ b/lib/connection_pool.rb @@ -3,7 +3,9 @@ require_relative "connection_pool/version" class ConnectionPool class Error < ::RuntimeError; end + class PoolShuttingDownError < ::ConnectionPool::Error; end + class TimeoutError < ::Timeout::Error; end end @@ -67,7 +69,7 @@ class ConnectionPool end end end - alias then with + alias_method :then, :with def checkout(options = {}) if ::Thread.current[@key] diff --git a/lib/connection_pool/timed_stack.rb b/lib/connection_pool/timed_stack.rb index 44fb310..a45bc28 100644 --- a/lib/connection_pool/timed_stack.rb +++ b/lib/connection_pool/timed_stack.rb @@ -49,7 +49,7 @@ class ConnectionPool::TimedStack @resource.broadcast end end - alias << push + alias_method :<<, :push ## # Retrieves a connection from the stack. If a connection is available it is @@ -87,7 +87,7 @@ class ConnectionPool::TimedStack # +:reload+ is +true+. 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 @shutdown_block = block diff --git a/lib/connection_pool/wrapper.rb b/lib/connection_pool/wrapper.rb index b242c6d..8630bee 100644 --- a/lib/connection_pool/wrapper.rb +++ b/lib/connection_pool/wrapper.rb @@ -30,7 +30,6 @@ class ConnectionPool METHODS.include?(id) || with { |c| c.respond_to?(id, *args) } end - # rubocop:disable Style/MethodMissingSuper # rubocop:disable Style/MissingRespondToMissing if ::RUBY_VERSION >= "3.0.0" def method_missing(name, *args, **kwargs, &block) diff --git a/test/test_connection_pool.rb b/test/test_connection_pool.rb index 3938da0..ab963de 100644 --- a/test/test_connection_pool.rb +++ b/test/test_connection_pool.rb @@ -339,7 +339,7 @@ class TestConnectionPool < Minitest::Test assert_equal 5, pool.do_something_with_block { 3 } assert_equal 6, pool.with { |net| net.fast } 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 def test_passthru_respond_to