Class: ConnectionPool::Wrapper

Inherits:
BasicObject
Defined in:
lib/connection_pool.rb

Constant Summary collapse

METHODS =
[:with, :pool_shutdown]

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Wrapper.



97
98
99
# File 'lib/connection_pool.rb', line 97

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



118
119
120
121
122
# File 'lib/connection_pool.rb', line 118

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

Instance Method Details

#pool_shutdown(&block) ⇒ Object



110
111
112
# File 'lib/connection_pool.rb', line 110

def pool_shutdown(&block)
  @pool.shutdown(&block)
end

#respond_to?(id, *args) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/connection_pool.rb', line 114

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

#withObject



101
102
103
104
105
106
107
108
# File 'lib/connection_pool.rb', line 101

def with
  conn = @pool.checkout
  begin
    yield conn
  ensure
    @pool.checkin
  end
end