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.


79
80
81
# File 'lib/connection_pool.rb', line 79

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


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

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)

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

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

#withObject


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

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