Sha256: e907a4ea1c582ebdc1bb143e60ff4731835c90a1d2b207aa432ea41e4bba49d1
Contents?: true
Size: 1.51 KB
Versions: 41
Compression:
Stored size: 1.51 KB
Contents
# Author:: Couchbase <info@couchbase.com> # Copyright:: 2013 Couchbase, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # if RUBY_VERSION.to_f < 1.9 raise LoadError, "connection_pool gem doesn't support ruby < 1.9" end require 'connection_pool' module Couchbase class ConnectionPool def initialize(pool_size = 5, *args) @pool = ::ConnectionPool.new(:size => pool_size) { ::Couchbase::Bucket.new(*args) } end def with yield @pool.checkout ensure @pool.checkin end def respond_to?(id, *args) super || @pool.with { |c| c.respond_to?(id, *args) } end def method_missing(name, *args, &block) define_proxy_method(name) send(name, *args, &block) end protected 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 end end
Version data entries
41 entries across 41 versions & 2 rubygems