module SwitchConnection::Model

Public Class Methods

included(model) click to toggle source
Calls superclass method
# File lib/switch_connection/model.rb, line 8
def self.included(model)
  super
  model.singleton_class.class_eval do
    include ClassMethods
    prepend MonkeyPatch
    def find_by_sql(*args, &block)
      if switch_point_proxy && connection.open_transactions.zero?
        with_slave do
          super
        end
      else
        super
      end
    end

    def count_by_sql(*args, &block)
      if switch_point_proxy && connection.open_transactions.zero?
        with_slave do
          super
        end
      else
        super
      end
    end
  end
end

Public Instance Methods

count_by_sql(*args, &block) click to toggle source
Calls superclass method
# File lib/switch_connection/model.rb, line 23
def count_by_sql(*args, &block)
  if switch_point_proxy && connection.open_transactions.zero?
    with_slave do
      super
    end
  else
    super
  end
end
find_by_sql(*args, &block) click to toggle source
Calls superclass method
# File lib/switch_connection/model.rb, line 13
def find_by_sql(*args, &block)
  if switch_point_proxy && connection.open_transactions.zero?
    with_slave do
      super
    end
  else
    super
  end
end
reload(*args, &block) click to toggle source
Calls superclass method
# File lib/switch_connection/model.rb, line 51
def reload(*args, &block)
  self.class.with_master do
    super(*args, &block)
  end
end
transaction_with(*models, &block) click to toggle source
# File lib/switch_connection/model.rb, line 47
def transaction_with(*models, &block)
  self.class.transaction_with(*models, &block)
end
with_master(&block) click to toggle source
# File lib/switch_connection/model.rb, line 39
def with_master(&block)
  self.class.with_master(&block)
end
with_slave(&block) click to toggle source
# File lib/switch_connection/model.rb, line 35
def with_slave(&block)
  self.class.with_slave(&block)
end
with_switch_point(new_switch_point_name, &block) click to toggle source
# File lib/switch_connection/model.rb, line 43
def with_switch_point(new_switch_point_name, &block)
  self.class.with_switch_point(new_switch_point_name, &block)
end