module Replidog::Model

Public Class Methods

extended(base) click to toggle source
# File lib/replidog/model.rb, line 5
def self.extended(base)
  base.class_attribute :proxy_handler, instance_writer: false
  base.proxy_handler = Replidog::ProxyHandler.new
  base.prepend InstanceMethodsWithReplidogSupport

  class << base
    prepend ClassMethodsWithReplidogSupport
  end
end

Public Instance Methods

replicated?() click to toggle source
# File lib/replidog/model.rb, line 66
def replicated?
  connection_config[:replications].present?
end
using(connection_name) { || ... } click to toggle source
# File lib/replidog/model.rb, line 70
def using(connection_name, &block)
  if replicated?
    _using(connection_name, &block)
  else
    if block_given?
      yield
    else
      self
    end
  end
end

Private Instance Methods

_using(connection_name) { || ... } click to toggle source
# File lib/replidog/model.rb, line 84
def _using(connection_name)
  if block_given?
    connection.current_connection_name = connection_name
    yield
  else
    ScopeProxy.new(klass: self, connection_name: connection_name)
  end
ensure
  connection.current_connection_name = nil if block_given?
end