Sha256: eefa75f861fa1bf7bbea77ff8edc5675d25d0bb2cc6f01c64fd2a7be2af70e0b
Contents?: true
Size: 1.19 KB
Versions: 18
Compression:
Stored size: 1.19 KB
Contents
module DbCharmer module ActiveRecord module MasterSlaveRouting module ClassMethods SLAVE_METHODS = [ :find_by_sql, :count_by_sql ] MASTER_METHODS = [ ] # I don't know any methods in AR::Base that change data directly w/o going to the relation object SLAVE_METHODS.each do |slave_method| class_eval <<-EOF, __FILE__, __LINE__ + 1 def #{slave_method}(*args, &block) first_level_on_slave do super(*args, &block) end end EOF end MASTER_METHODS.each do |master_method| class_eval <<-EOF, __FILE__, __LINE__ + 1 def #{master_method}(*args, &block) on_master do super(*args, &block) end end EOF end end module InstanceMethods MASTER_METHODS = [ :reload ] MASTER_METHODS.each do |master_method| class_eval <<-EOF, __FILE__, __LINE__ + 1 def #{master_method}(*args, &block) self.class.on_master do super(*args, &block) end end EOF end end end end end
Version data entries
18 entries across 18 versions & 2 rubygems