Module: DbCharmer::ActiveRecord::MultiDbProxy::MasterSlaveClassMethods
- Defined in:
- lib/db_charmer/active_record/multi_db_proxy.rb
Instance Method Summary collapse
- #first_level_on_slave ⇒ Object
- #on_master(proxy_target = nil, &block) ⇒ Object
- #on_slave(con = nil, proxy_target = nil, &block) ⇒ Object
Instance Method Details
#first_level_on_slave ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/db_charmer/active_record/multi_db_proxy.rb', line 75 def first_level_on_slave first_level = db_charmer_top_level_connection? && on_master.connection.open_transactions.zero? if first_level && db_charmer_force_slave_reads? && db_charmer_slaves.any? on_slave { yield } else yield end end |
#on_master(proxy_target = nil, &block) ⇒ Object
71 72 73 |
# File 'lib/db_charmer/active_record/multi_db_proxy.rb', line 71 def on_master(proxy_target = nil, &block) on_db(db_charmer_default_connection, proxy_target, &block) end |
#on_slave(con = nil, proxy_target = nil, &block) ⇒ Object
65 66 67 68 69 |
# File 'lib/db_charmer/active_record/multi_db_proxy.rb', line 65 def on_slave(con = nil, proxy_target = nil, &block) con ||= db_charmer_random_slave raise ArgumentError, "No slaves found in the class and no slave connection given" unless con on_db(con, proxy_target, &block) end |