Module: DbCharmer::MultiDbProxy::ClassMethods

Defined in:
lib/db_charmer/multi_db_proxy.rb

Instance Method Summary collapse

Instance Method Details

#on_db(con, proxy_target = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/db_charmer/multi_db_proxy.rb', line 19

def on_db(con, proxy_target = nil)
  proxy_target ||= self
  
  # Chain call
  return OnDbProxy.new(proxy_target, con) unless block_given?

  # Block call
  begin
    self.db_charmer_connection_level += 1
    old_proxy = db_charmer_connection_proxy
    switch_connection_to(con, DbCharmer.migration_connections_should_exist?)
    yield(proxy_target)
  ensure
    switch_connection_to(old_proxy)
    self.db_charmer_connection_level -= 1
  end
end