Sha256: c651c58239edb831f4756587a79b441d479d9fe19905dcf3f637778d5b945c5a
Contents?: true
Size: 777 Bytes
Versions: 2
Compression:
Stored size: 777 Bytes
Contents
module ActiveRecord class Base class << self alias_method :connection_without_slavery, :connection def connection case Thread.current[:slavery] when :slave Slavery.connection_holder.connection_without_slavery when :master, NilClass connection_without_slavery else raise Slavery::Error.new("invalid target: #{Thread.current[:slavery]}") end end # Generate scope at top level e.g. User.on_slave def on_slave # Why where(nil)? # http://stackoverflow.com/questions/18198963/with-rails-4-model-scoped-is-deprecated-but-model-all-cant-replace-it context = where(nil) context.slavery_target = :slave context end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
slavery-2.1.1 | lib/slavery/active_record/base.rb |
slavery-2.1.0 | lib/slavery/active_record/base.rb |