File: wrapper.rb

package info (click to toggle)
ruby-connection-pool 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 228 kB
  • sloc: ruby: 1,252; makefile: 6
file content (43 lines) | stat: -rw-r--r-- 808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class ConnectionPool
  class Wrapper < ::BasicObject
    METHODS = [:with, :pool_shutdown, :wrapped_pool]

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

    def wrapped_pool
      @pool
    end

    def with(**, &)
      @pool.with(**, &)
    end

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

    def pool_size
      @pool.size
    end

    def pool_available
      @pool.available
    end

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

    def respond_to_missing?(id, *, **)
      with { |c| c.respond_to?(id, *, **) }
    end

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