Created
October 12, 2008 01:13
-
-
Save bturnbull/16344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First extend ActiveRecord::Base to allow us to override connections | |
module ActiveRecord | |
class Base | |
# Sets the active connection to conn and runs the given block. Active | |
# connection is reset to it's previous value once the block finishes. | |
def self.using_connection(conn) | |
old_connection = use_connection(conn) | |
ret = yield if block_given? | |
use_connection(old_connection) | |
ret | |
end | |
# Sets the active connection to conn, returns the previously active connection | |
def self.use_connection(conn) | |
old_active_connection = active_connections[active_connection_name] | |
active_connections[active_connection_name] = conn | |
old_active_connection | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment