public
Description: ActiveRecord connection proxy for master/slave connections
Clone URL: git://github.com/technoweenie/masochism.git
allow some more flexibility on when exactly the proxy is setup

git-svn-id: http://ar-code.svn.engineyard.com/plugins/masochism@31 
d98f8484-0aa7-43af-80ea-302c351499d6
rick (author)
Fri Oct 05 22:59:57 -0700 2007
commit  720142f99ad2049d15ea4bd2583f8b8f6914c233
tree    af95e948370b4bd8889b3ba49b38918ec0c155e2
parent  394227098149fae52d95a6be02acf07d64196453
...
5
6
7
8
9
10
 
 
 
11
12
13
14
15
 
 
 
 
 
 
 
 
 
16
17
18
...
5
6
7
 
 
 
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
0
@@ -5,14 +5,23 @@ module ActiveReload
0
   end
0
 
0
   class ConnectionProxy
0
- def initialize
0
- @slave = ActiveRecord::Base.connection
0
- @master = ActiveReload::MasterDatabase.connection
0
+ def initialize(master, slave)
0
+ @slave = slave.connection
0
+ @master = master.connection
0
       @current = @slave
0
     end
0
     
0
     attr_accessor :slave, :master
0
 
0
+ def self.setup!
0
+ setup_for ActiveReload::MasterDatabase
0
+ end
0
+
0
+ def self.setup_for(master, slave = nil)
0
+ slave ||= ActiveRecord::Base
0
+ ActiveRecord::Base.active_connections[slave.name] = new(master, slave)
0
+ end
0
+
0
     def with_master
0
       set_to_master!
0
       yield

Comments

    No one has commented yet.