master_slave_adapter_tcurdt 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,5 @@
1
1
  ActiveRecord::Base.class_eval do
2
2
 
3
- def reload_with_master( options = nil )
4
- ActiveRecord::ConnectionAdapters::MasterSlaveAdapter.with_master do
5
- reload_without_master( options )
6
- end
7
- end
8
-
9
- alias_method_chain :reload, :master
10
-
11
3
  class << self
12
4
 
13
5
  # Call this method to force a block of code to use the master connection
@@ -51,18 +43,6 @@ ActiveRecord::Base.class_eval do
51
43
  end
52
44
  end
53
45
 
54
- def transaction_with_master(*args, &block)
55
- if connection.respond_to? :transaction
56
- connection.transaction do
57
- transaction_without_master(*args, &block)
58
- end
59
- else
60
- transaction_without_master(*args, &block)
61
- end
62
- end
63
- alias_method_chain :transaction, :master
64
-
65
-
66
46
  def master_slave_connection( config )
67
47
  config = config.symbolize_keys
68
48
  raise "You must provide a configuration for the master database - #{config.inspect}" if config[:master].blank?
@@ -87,12 +67,31 @@ ActiveRecord::Base.class_eval do
87
67
  ActiveRecord::ConnectionAdapters::MasterSlaveAdapter.new(config)
88
68
  end
89
69
 
70
+ def transaction_with_master(*args, &block)
71
+ if connection.respond_to? :transaction
72
+ connection.transaction do
73
+ transaction_without_master(*args, &block)
74
+ end
75
+ else
76
+ transaction_without_master(*args, &block)
77
+ end
78
+ end
79
+ alias_method_chain :transaction, :master
80
+
90
81
  def columns_with_master
91
- ActiveRecord::ConnectionAdapters::MasterSlaveAdapter.with_master do
82
+ with_master do
92
83
  columns_without_master
93
84
  end
94
85
  end
95
86
  alias_method_chain :columns, :master
96
87
 
97
88
  end
89
+
90
+ def reload_with_master(options = nil)
91
+ ActiveRecord::Base.with_master do
92
+ reload_without_master(options)
93
+ end
94
+ end
95
+ alias_method_chain :reload, :master
96
+
98
97
  end
@@ -152,9 +152,9 @@ module ActiveRecord
152
152
  end
153
153
 
154
154
  def transaction(*args)
155
- puts "<transaction"
155
+ # puts "<transaction"
156
156
  yield
157
- puts "</transaction"
157
+ # puts "</transaction"
158
158
  update_clock
159
159
  end
160
160
 
@@ -187,7 +187,7 @@ module ActiveRecord
187
187
  private
188
188
 
189
189
  def update_clock
190
- puts " update clock"
190
+ # puts " update clock"
191
191
  # update the clock, if there was problem keep using the old one
192
192
  self.current_clock[0] = master_clock || self.current_clock[0]
193
193
  # it's a write so from now on we use the master connection
@@ -245,7 +245,7 @@ module ActiveRecord
245
245
  end
246
246
 
247
247
  def master_clock
248
- puts " master clock"
248
+ # puts " master clock"
249
249
  connection = connect_to_master
250
250
  if status = connection.uncached { connection.select_one("SHOW MASTER STATUS") }
251
251
  Clock.new(status['File'], status['Position'])
@@ -253,7 +253,7 @@ module ActiveRecord
253
253
  end
254
254
 
255
255
  def slave_clock
256
- puts " slave clock"
256
+ # puts " slave clock"
257
257
  connection = connect_to_slave
258
258
  if status = connection.uncached { connection.select_one("SHOW SLAVE STATUS") }
259
259
  Clock.new(status['Relay_Master_Log_File'], status['Exec_Master_Log_Pos'])
@@ -1,3 +1,3 @@
1
1
  module MasterSlaveAdapter
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -75,6 +75,9 @@ describe ActiveRecord::ConnectionAdapters::MasterSlaveAdapter do
75
75
 
76
76
  end
77
77
 
78
+ it "should call 'columns' on master" do
79
+ end
80
+
78
81
  ActiveRecord::ConnectionAdapters::MasterSlaveAdapter::SELECT_METHODS.each do |method|
79
82
 
80
83
  it "should send the method '#{method}' to the slave connection" do
@@ -334,27 +337,27 @@ describe ActiveRecord::ConnectionAdapters::MasterSlaveAdapter do
334
337
 
335
338
  old_clock = zero
336
339
  new_clock = ActiveRecord::Base.with_consistency(old_clock) do
337
- puts "slave: select"
340
+ # puts "slave: select"
338
341
  ActiveRecord::Base.connection.send('select_all', 'testing') # slave s=0 m=0
339
- puts "master: update"
342
+ # puts "master: update"
340
343
  ActiveRecord::Base.connection.send('update', 'testing') # master s=0 m=1
341
- puts "master: select"
344
+ # puts "master: select"
342
345
  ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=1
343
346
 
344
347
  ActiveRecord::Base.transaction do
345
- puts "master: select"
348
+ # puts "master: select"
346
349
  ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=1
347
- puts "master: update"
350
+ # puts "master: update"
348
351
  ActiveRecord::Base.connection.send('update', 'testing') # master s=0 m=1
349
- puts "master: select"
352
+ # puts "master: select"
350
353
  ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=1
351
354
  end
352
355
 
353
- puts "master: select"
356
+ # puts "master: select"
354
357
  ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=2
355
- puts "master: update"
358
+ # puts "master: update"
356
359
  ActiveRecord::Base.connection.send('update', 'testing') # master s=0 m=3
357
- puts "master: select"
360
+ # puts "master: select"
358
361
  ActiveRecord::Base.connection.send('select_all', 'testing') # master s=0 m=3
359
362
  end
360
363
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mauricio Linhares