mirror of
https://github.com/mperham/connection_pool
synced 2023-03-27 23:22:21 -04:00
Restore Wrapper
inheriting from BasicObject
. Closes #16.
This commit is contained in:
parent
29cd6d7b56
commit
f0cb4ea11f
2 changed files with 7 additions and 2 deletions
|
@ -75,7 +75,9 @@ class ConnectionPool
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
class Wrapper
|
class Wrapper < ::BasicObject
|
||||||
|
METHODS = [:with, :with_connection]
|
||||||
|
|
||||||
def initialize(options = {}, &block)
|
def initialize(options = {}, &block)
|
||||||
@pool = ::ConnectionPool.new(options, &block)
|
@pool = ::ConnectionPool.new(options, &block)
|
||||||
end
|
end
|
||||||
|
@ -88,7 +90,7 @@ class ConnectionPool
|
||||||
alias_method :with_connection, :with
|
alias_method :with_connection, :with
|
||||||
|
|
||||||
def respond_to?(id, *args)
|
def respond_to?(id, *args)
|
||||||
super(id, *args) || @pool.with { |c| c.respond_to?(id, *args) }
|
METHODS.include?(id) || @pool.with { |c| c.respond_to?(id, *args) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(name, *args, &block)
|
def method_missing(name, *args, &block)
|
||||||
|
|
|
@ -72,7 +72,10 @@ class TestConnectionPool < MiniTest::Unit::TestCase
|
||||||
assert_equal 2, pool.do_something
|
assert_equal 2, pool.do_something
|
||||||
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 }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_passthru_respond_to
|
||||||
|
pool = ConnectionPool.wrap(:timeout => 0.1, :size => 1) { NetworkConnection.new }
|
||||||
assert pool.respond_to?(:with)
|
assert pool.respond_to?(:with)
|
||||||
assert pool.respond_to?(:do_something)
|
assert pool.respond_to?(:do_something)
|
||||||
assert pool.respond_to?(:do_magic)
|
assert pool.respond_to?(:do_magic)
|
||||||
|
|
Loading…
Reference in a new issue