Class: ActiveRecordHostPool::PoolProxy
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveRecordHostPool::PoolProxy
- Defined in:
- lib/active_record_host_pool/pool_proxy.rb
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #__setobj__(spec) ⇒ Object
- #automatic_reconnect=(value) ⇒ Object
- #checkin(cx) ⇒ Object
-
#checkout(*args, &block) ⇒ Object
by the time we are patched into ActiveRecord, the current thread has already established a connection.
- #clear_reloadable_connections! ⇒ Object
- #connection(*args) ⇒ Object
- #disconnect! ⇒ Object
-
#initialize(spec) ⇒ PoolProxy
constructor
A new instance of PoolProxy.
- #spec ⇒ Object
- #with_connection ⇒ Object
Constructor Details
#initialize(spec) ⇒ PoolProxy
Returns a new instance of PoolProxy.
16 17 18 19 20 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 16 def initialize(spec) super(spec) @spec = spec @config = spec.config end |
Instance Method Details
#__getobj__ ⇒ Object
22 23 24 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 22 def __getobj__ _connection_pool end |
#__setobj__(spec) ⇒ Object
26 27 28 29 30 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 26 def __setobj__(spec) @spec = spec @config = spec.config @_pool_key = nil end |
#automatic_reconnect=(value) ⇒ Object
75 76 77 78 79 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 75 def automatic_reconnect=(value) p = _connection_pool(false) return unless p p.automatic_reconnect = value if p.respond_to?(:automatic_reconnect=) end |
#checkin(cx) ⇒ Object
55 56 57 58 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 55 def checkin(cx) cx = cx.unproxied _connection_pool.checkin(cx) end |
#checkout(*args, &block) ⇒ Object
by the time we are patched into ActiveRecord, the current thread has already established a connection. thus we need to patch both connection and checkout/checkin
50 51 52 53 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 50 def checkout(*args, &block) cx = _connection_pool.checkout(*args, &block) _connection_proxy_for(cx, @config[:database]) end |
#clear_reloadable_connections! ⇒ Object
81 82 83 84 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 81 def clear_reloadable_connections! _connection_pool.clear_reloadable_connections! _clear_connection_proxy_cache end |
#connection(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 36 def connection(*args) begin real_connection = _connection_pool.connection(*args) _connection_proxy_for(real_connection, @config[:database]) rescue Exception => e if rescuable_errors.any? { |r| e.is_a?(r) } _connection_pools.delete(_pool_key) end Kernel.raise(e) end end |
#disconnect! ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 67 def disconnect! p = _connection_pool(false) return unless p p.disconnect! p.automatic_reconnect = true if p.respond_to?(:automatic_reconnect=) _clear_connection_proxy_cache end |
#spec ⇒ Object
32 33 34 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 32 def spec @spec end |
#with_connection ⇒ Object
60 61 62 63 64 65 |
# File 'lib/active_record_host_pool/pool_proxy.rb', line 60 def with_connection cx = checkout yield cx ensure checkin cx end |