Class: Couchbase::ConnectionPool

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

Instance Method Summary collapse

Constructor Details

#initialize(pool_size = 5, *args) ⇒ ConnectionPool

Returns a new instance of ConnectionPool.


26
27
28
# File 'lib/couchbase/connection_pool.rb', line 26

def initialize(pool_size = 5, *args)
  @pool = ::ConnectionPool.new(:size => pool_size) { ::Couchbase::Bucket.new(*args) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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


40
41
42
43
# File 'lib/couchbase/connection_pool.rb', line 40

def method_missing(name, *args, &block)
  define_proxy_method(name)
  send(name, *args, &block)
end

Instance Method Details

#define_proxy_method(name) ⇒ Object (protected)


47
48
49
50
51
52
53
54
55
# File 'lib/couchbase/connection_pool.rb', line 47

def define_proxy_method(name)
  self.class.class_eval <<-RUBY
    def #{name}(*args, &block)
      @pool.with do |connection|
        connection.send(#{name.inspect}, *args, &block)
      end
    end
  RUBY
end

#respond_to?(id, *args) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/couchbase/connection_pool.rb', line 36

def respond_to?(id, *args)
  super || @pool.with { |c| c.respond_to?(id, *args) }
end

#withObject


30
31
32
33
34
# File 'lib/couchbase/connection_pool.rb', line 30

def with
  yield @pool.checkout
ensure
  @pool.checkin
end