Class: Flounder::ConnectionPool
- Inherits:
-
Object
- Object
- Flounder::ConnectionPool
- Defined in:
- lib/flounder/connection_pool.rb
Defined Under Namespace
Classes: Spec
Instance Attribute Summary collapse
-
#pg_conn_args ⇒ Object
readonly
Returns the value of attribute pg_conn_args.
Instance Method Summary collapse
-
#checkout ⇒ Object
Checks out a connection from the pool.
-
#initialize(pg_conn_args) ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
-
#spec ⇒ Object
This is needed to conform to arels interface.
-
#with_connection ⇒ Object
Checks out a connection from the pool and yields it to the block.
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_args ⇒ Object (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
#checkout ⇒ Object
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 |
#spec ⇒ Object
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_connection ⇒ Object
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 |