1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
class ConnectionPool
class Wrapper < ::BasicObject
METHODS = [:with, :pool_shutdown, :wrapped_pool]
def initialize(options = {}, &block)
@pool = options.fetch(:pool) { ::ConnectionPool.new(options, &block) }
end
def wrapped_pool
@pool
end
def with(&block)
@pool.with(&block)
end
def pool_shutdown(&block)
@pool.shutdown(&block)
end
def pool_size
@pool.size
end
def pool_available
@pool.available
end
def respond_to?(id, *args)
METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
end
# rubocop:disable Style/MissingRespondToMissing
if ::RUBY_VERSION >= "3.0.0"
def method_missing(name, *args, **kwargs, &block)
with do |connection|
connection.send(name, *args, **kwargs, &block)
end
end
elsif ::RUBY_VERSION >= "2.7.0"
ruby2_keywords def method_missing(name, *args, &block)
with do |connection|
connection.send(name, *args, &block)
end
end
else
def method_missing(name, *args, &block)
with do |connection|
connection.send(name, *args, &block)
end
end
end
# rubocop:enable Style/MethodMissingSuper
# rubocop:enable Style/MissingRespondToMissing
end
end
|