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.



23
24
25
# File 'lib/couchbase/connection_pool.rb', line 23

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



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

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

Instance Method Details

#define_proxy_method(name) ⇒ Object (protected)



44
45
46
47
48
49
50
51
52
# File 'lib/couchbase/connection_pool.rb', line 44

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)


33
34
35
# File 'lib/couchbase/connection_pool.rb', line 33

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

#withObject



27
28
29
30
31
# File 'lib/couchbase/connection_pool.rb', line 27

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