Module: MultiDb::ActiveRecordExtensions::ClassMethods
- Defined in:
- lib/multi_db/active_record_extensions.rb
Instance Method Summary collapse
-
#cache(&block) ⇒ Object
make caching always use the ConnectionProxy.
- #hijack_connection ⇒ Object
- #inherited(child) ⇒ Object
-
#transaction(options = {}, &block) ⇒ Object
Make sure transactions always switch to the master.
Instance Method Details
#cache(&block) ⇒ Object
make caching always use the ConnectionProxy
30 31 32 33 34 35 36 |
# File 'lib/multi_db/active_record_extensions.rb', line 30 def cache(&block) if ActiveRecord::Base.configurations.blank? yield else self.connection_proxy.cache(&block) end end |
#hijack_connection ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/multi_db/active_record_extensions.rb', line 43 def hijack_connection return if ConnectionProxy.master_models.include?(self.to_s) logger.info "[MULTIDB] hijacking connection for #{self.to_s}" class << self def connection self.connection_proxy end end end |
#inherited(child) ⇒ Object
38 39 40 41 |
# File 'lib/multi_db/active_record_extensions.rb', line 38 def inherited(child) super child.hijack_connection end |
#transaction(options = {}, &block) ⇒ Object
Make sure transactions always switch to the master
21 22 23 24 25 26 27 |
# File 'lib/multi_db/active_record_extensions.rb', line 21 def transaction( = {}, &block) if self.connection.kind_of?(ConnectionProxy) super else self.connection_proxy.with_master { super } end end |