Sha256: c132b3a23dfffc3a8f5792f9fe4568a237fa44a11c52c5e80ef1b2eadaf1b5cd

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

module ActiveRecord::Turntable
  module ActiveRecordConnectionMethods
    def self.included(base)
      base.alias_method_chain :reload, :master
    end

    def reload_with_master(*args, &block)
      connection.with_master { reload_without_master }
    end
  end

  class PoolProxy
    def initialize(proxy)
      @proxy = proxy
    end

    def connection
      @proxy
    end

    def spec
      @proxy.spec
    end


    def with_connection
      yield @proxy
    end

    def connected?
      @proxy.connected?
    end

    if ActiveRecord::VERSION::STRING > '3.1'
      %w(columns_hash column_defaults primary_keys).each do |name|
        define_method(name.to_sym) do
          @proxy.send(name.to_sym)
        end
      end

      %w(table_exists? columns).each do |name|
        define_method(name.to_sym) do |*args|
          @proxy.send(name.to_sym, *args)
        end
      end
    end

    %w(disconnect! release_connection clear_all_connections! clear_active_connections! clear_reloadable_connections! clear_stale_cached_connections! verify_active_connections!).each do |name|
      define_method(name.to_sym) do
        @proxy.master.connection_pool.send(name.to_sym)
        @proxy.seq.connection_pool.try(name.to_sym) if @proxy.respond_to?(:seq)
        @proxy.shards.values.each do |pool|
          pool.connection_pool.send(name.to_sym)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activerecord-turntable-1.1.2 lib/active_record/turntable/pool_proxy.rb
activerecord-turntable-1.1.1 lib/active_record/turntable/pool_proxy.rb
activerecord-turntable-1.1.0 lib/active_record/turntable/pool_proxy.rb