Sha256: e05507accbe56a8cea3be72007de10cdb276265d08673b45f74deb94d5c15ffd

Contents?: true

Size: 1.45 KB

Versions: 7

Compression:

Stored size: 1.45 KB

Contents

module FreshConnection
  module Extend
    module ArBase
      def connection
        if FreshConnection::AccessControl.slave_access?
          if logger && logger.debug?
            slave_connection.tap{|c| c.slave_group = slave_group }
          else
            slave_connection
          end
        else
          super
        end
      end

      def read_master
        all.read_master
      end

      def with_master(&block)
        all.manage_access(false, &block)
      end

      def establish_fresh_connection(slave_group = nil)
        slave_connection_handler.establish_connection(name, slave_group)
      end

      def slave_connection
        slave_connection_handler.connection(self)
      end

      def clear_all_slave_connections!
        slave_connection_handler.clear_all_connections!
      end

      def master_db_only!
        @_fresh_connection_master_only = true
      end

      def master_db_only?
        @_fresh_connection_master_only ||=
          (self != ActiveRecord::Base && superclass.master_db_only?)
      end

      def slave_connection_put_aside!
        slave_connection_handler.put_aside!
      end

      def slave_connection_recovery?
        slave_connection_handler.recovery?(self)
      end

      def slave_group
        slave_connection_handler.slave_group(self)
      end

      private

      def slave_connection_handler
        @@slave_connection_handler ||= FreshConnection::SlaveConnectionHandler.new
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fresh_connection-2.1.2 lib/fresh_connection/extend/ar_base.rb
fresh_connection-2.1.1 lib/fresh_connection/extend/ar_base.rb
fresh_connection-2.1.0 lib/fresh_connection/extend/ar_base.rb
fresh_connection-2.0.4 lib/fresh_connection/extend/ar_base.rb
fresh_connection-2.0.3 lib/fresh_connection/extend/ar_base.rb
fresh_connection-2.0.2 lib/fresh_connection/extend/ar_base.rb
fresh_connection-2.0.1 lib/fresh_connection/extend/ar_base.rb