Sha256: 9a432dd69356eb59eb57a2ffc3396345246f4ab5c19e8f65c1f47ec82aaa88c0
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
require 'active_support/core_ext/class/attribute' require 'fresh_connection/slave_connection_handler' require 'fresh_connection/access_control' module FreshConnection module Extend module ArBase def self.extended(base) base.class_attribute :slave_connection_handler, :instance_writer => false base.slave_connection_handler = FreshConnection::SlaveConnectionHandler.new end if FreshConnection.rails_4? delegate :read_master, to: :all elsif FreshConnection.rails_3? delegate :read_master, to: :scoped end def manage_access(slave_access, &block) if master_db_only? FreshConnection::AccessControl.force_master_access(&block) else FreshConnection::AccessControl.access(slave_access, &block) end end def establish_fresh_connection(slave_group = nil) slave_connection_handler.establish_connection(name, slave_group) end def slave_connection slave_connection_handler.connection(self) end def master_db_only! @_fresh_connection_master_only = true end def master_db_only? @_fresh_connection_master_only || (self != ActiveRecord::Base && superclass.master_db_only?) end def put_aside! slave_connection_handler.put_aside! end def recovery(failure_connection, exception) slave_connection_handler.recovery(self, failure_connection, exception) end def slave_group slave_connection_handler.slave_group(self) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fresh_connection-0.4.0 | lib/fresh_connection/extend/ar_base.rb |