Sha256: b48c81cbce8ff89c38dac1b7d4cb7e1f67b172839f30096cf9dc692ed5dcc1d8

Contents?: true

Size: 1.45 KB

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
fresh_connection-2.0.0 lib/fresh_connection/extend/ar_base.rb