Class: Ensql::PoolWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/ensql/pool_wrapper.rb

Overview

Wrap a 3rd-party connection pool with a standard interface. Connections can be checked out by #with

Instance Method Summary collapse

Constructor Details

#initialize(&connection_block) ⇒ PoolWrapper

Wraps a block for accessing a connection from a pool.

PoolWrapper.new do |client_block|
  my_connection_pool.with_connection(&client_block)
end


11
12
13
# File 'lib/ensql/pool_wrapper.rb', line 11

def initialize(&connection_block)
  @connection_block = connection_block
end

Instance Method Details

#with {|connection| ... } ⇒ Object

Get a connection from our source pool

Yields:

  • (connection)

    the database-specific connection



17
18
19
# File 'lib/ensql/pool_wrapper.rb', line 17

def with(&client_block)
  @connection_block.call(client_block)
end