Sha256: a073572fddf60272a423c693e40828c45ddf1e34c8100ebf0a94b6624090b174

Contents?: true

Size: 966 Bytes

Versions: 2

Compression:

Stored size: 966 Bytes

Contents

module Slaver
  class Proxy
    include Singleton

    attr_reader :connection_pool, :klass

    def for_config(klass, config_name)
      @klass = klass
      @connection_pool = klass.pools[config_name]

      self
    end

    def connected?
      connection_pool.connected?
    end

    def clear_all_connections!
      connection_pool.disconnect!
    end

    def clear_active_connections!
      connection_pool.release_connection
    end

    def safe_connection
      connection_pool.automatic_reconnect = true
      if !connection_pool.connected? && klass.connection_without_proxy.query_cache_enabled
        connection_pool.connection.enable_query_cache!
      end
      connection_pool.connection
    end

    def method_missing(method, *args, &block)
      safe_connection.send(method, *args, &block)
    end

    def respond_to_missing?(method, include_private = false)
      safe_connection.respond_to?(method, include_private) || super
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slaver-0.2.3 lib/slaver/proxy.rb
slaver-0.2.2 lib/slaver/proxy.rb