Class: Spinel::ConnectionPoolProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/spinel/connection_pool_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool) ⇒ ConnectionPoolProxy

Returns a new instance of ConnectionPoolProxy.

Raises:

  • (ArgumentError)


3
4
5
6
# File 'lib/spinel/connection_pool_proxy.rb', line 3

def initialize pool
  raise ArgumentError, "Should only proxy ConnectionPool!" unless self.class.should_proxy?(pool)
  @pool = pool
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



8
9
10
# File 'lib/spinel/connection_pool_proxy.rb', line 8

def method_missing name, *args, &block
  @pool.with { |x| x.send(name, *args, &block) }
end

Class Method Details

.proxy_if_needed(conn) ⇒ Object



20
21
22
# File 'lib/spinel/connection_pool_proxy.rb', line 20

def self.proxy_if_needed(conn)
  should_proxy?(conn) ? self.new(conn) : conn
end

.should_proxy?(conn) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/spinel/connection_pool_proxy.rb', line 16

def self.should_proxy?(conn)
  defined?(::ConnectionPool) && conn.is_a?(::ConnectionPool)
end

Instance Method Details

#respond_to_missing?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/spinel/connection_pool_proxy.rb', line 12

def respond_to_missing? name, include_all = false
  @pool.with { |x| x.respond_to?(name, include_all) }
end