Class: ConnectionPool::Wrapper

Inherits:
BasicObject
Defined in:
lib/connection_pool.rb

Constant Summary collapse

METHODS =
[:with]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Wrapper

Returns a new instance of Wrapper.



84
85
86
# File 'lib/connection_pool.rb', line 84

def initialize(options = {}, &block)
  @pool = ::ConnectionPool.new(options, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



98
99
100
101
102
# File 'lib/connection_pool.rb', line 98

def method_missing(name, *args, &block)
  @pool.with do |connection|
    connection.send(name, *args, &block)
  end
end

Instance Method Details

#respond_to?(id, *args) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/connection_pool.rb', line 94

def respond_to?(id, *args)
  METHODS.include?(id) || @pool.with { |c| c.respond_to?(id, *args) }
end

#withObject



88
89
90
91
92
# File 'lib/connection_pool.rb', line 88

def with
  yield @pool.checkout
ensure
  @pool.checkin
end