Class: Switchman::ConnectionPoolProxy
- Inherits:
-
Object
- Object
- Switchman::ConnectionPoolProxy
- Defined in:
- lib/switchman/connection_pool_proxy.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
Instance Method Summary collapse
- #active_shard ⇒ Object
- #connection ⇒ Object
- #current_pool ⇒ Object
- #default_pool ⇒ Object
-
#initialize(category, default_pool, shard_connection_pools) ⇒ ConnectionPoolProxy
constructor
A new instance of ConnectionPoolProxy.
Constructor Details
#initialize(category, default_pool, shard_connection_pools) ⇒ ConnectionPoolProxy
Returns a new instance of ConnectionPoolProxy.
12 13 14 15 16 |
# File 'lib/switchman/connection_pool_proxy.rb', line 12 def initialize(category, default_pool, shard_connection_pools) @category = category @default_pool = default_pool @connection_pools = shard_connection_pools end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
6 7 8 |
# File 'lib/switchman/connection_pool_proxy.rb', line 6 def category @category end |
Instance Method Details
#active_shard ⇒ Object
18 19 20 |
# File 'lib/switchman/connection_pool_proxy.rb', line 18 def active_shard Shard.current(@category) end |
#connection ⇒ Object
29 30 31 32 |
# File 'lib/switchman/connection_pool_proxy.rb', line 29 def connection pool = current_pool pool.connection end |
#current_pool ⇒ Object
22 23 24 25 26 27 |
# File 'lib/switchman/connection_pool_proxy.rb', line 22 def current_pool pool = self.default_pool if active_shard.default? pool = @connection_pools[pool_key] ||= create_pool unless pool pool.shard = active_shard pool end |
#default_pool ⇒ Object
8 9 10 |
# File 'lib/switchman/connection_pool_proxy.rb', line 8 def default_pool @default_pool end |