class DbCharmer::ActiveRecord::MultiDbProxy::OnDbProxy
Simple proxy class that switches connections and then proxies all the calls This class is used to implement chained on_db calls
Public Class Methods
new(proxy_target, slave)
click to toggle source
# File lib/db_charmer/active_record/multi_db_proxy.rb, line 10 def initialize(proxy_target, slave) @proxy_target = proxy_target @slave = slave end
Private Instance Methods
method_missing(meth, *args, &block)
click to toggle source
# File lib/db_charmer/active_record/multi_db_proxy.rb, line 17 def method_missing(meth, *args, &block) # Switch connection and proxy the method call @proxy_target.on_db(@slave) do |proxy_target| res = proxy_target.__send__(meth, *args, &block) # If result is a scope/association, return a new proxy for it, otherwise return the result itself (res.proxy?) ? OnDbProxy.new(res, @slave) : res end end