Class: Flounder::ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/flounder/connection_pool.rb

Defined Under Namespace

Classes: Spec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pg_conn_args) ⇒ ConnectionPool

Returns a new instance of ConnectionPool.



7
8
9
10
11
12
# File 'lib/flounder/connection_pool.rb', line 7

def initialize pg_conn_args
  @pg_conn_args = pg_conn_args
  @pool = ::ConnectionPool.new(size: 5, timeout: 5) {
    Connection.new(pg_conn_args)
  }
end

Instance Attribute Details

#pg_conn_argsObject (readonly)

Returns the value of attribute pg_conn_args.



5
6
7
# File 'lib/flounder/connection_pool.rb', line 5

def pg_conn_args
  @pg_conn_args
end

Instance Method Details

#checkoutObject

Checks out a connection from the pool. You have to return this connection manually.



27
28
29
# File 'lib/flounder/connection_pool.rb', line 27

def checkout
  @pool.checkout
end

#specObject

This is needed to conform to arels interface.



35
36
37
# File 'lib/flounder/connection_pool.rb', line 35

def spec
  Spec.new(adapter: 'pg')
end

#with_connectionObject

Checks out a connection from the pool and yields it to the block. The connection is returned to the pool at the end of the block; don’t hold on to it.



18
19
20
21
22
# File 'lib/flounder/connection_pool.rb', line 18

def with_connection
  @pool.with do |conn|
    yield conn
  end
end