Skip to content

Commit

Permalink
Move wrapper into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Jun 2, 2020
1 parent dd5dac5 commit f93e357
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/connection_pool.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'connection_pool/version'
require 'connection_pool/errors'
require 'connection_pool/timed_stack'
require 'connection_pool/wrapper'


# Generic connection pool class for sharing a limited number of objects or network connections
Expand Down
39 changes: 39 additions & 0 deletions lib/connection_pool/wrapper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class ConnectionPool
class Wrapper < ::BasicObject
METHODS = [:with, :pool_shutdown, :wrapped_pool]

def initialize(options = {}, &block)
@pool = options.fetch(:pool) { ::ConnectionPool.new(options, &block) }
end

def wrapped_pool
@pool
end

def with(&block)
@pool.with(&block)
end

def pool_shutdown(&block)
@pool.shutdown(&block)
end

def pool_size
@pool.size
end

def pool_available
@pool.available
end

def respond_to?(id, *args)
METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
end

def method_missing(name, *args, &block)
with do |connection|
connection.send(name, *args, &block)
end
end
end
end

0 comments on commit f93e357

Please sign in to comment.