From 9a5ae52da2cdbc2f49cdd37ddd12daa0eaec4b3c Mon Sep 17 00:00:00 2001 From: nagaya Date: Mon, 29 Apr 2024 15:42:32 +0900 Subject: [PATCH] Add code --- lib/arproxy/chain_tail.rb | 2 +- lib/arproxy/proxy_chain.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/arproxy/chain_tail.rb b/lib/arproxy/chain_tail.rb index cf35f83..9311f4c 100644 --- a/lib/arproxy/chain_tail.rb +++ b/lib/arproxy/chain_tail.rb @@ -5,7 +5,7 @@ def initialize(proxy_chain) end def execute(sql, name=nil, **kwargs) - self.proxy_chain.connection.execute_without_arproxy sql, name, **kwargs + self.proxy_chain.connection.send(:execute_without_arproxy, sql, name, **kwargs) end end end diff --git a/lib/arproxy/proxy_chain.rb b/lib/arproxy/proxy_chain.rb index e884795..2fb4a1c 100644 --- a/lib/arproxy/proxy_chain.rb +++ b/lib/arproxy/proxy_chain.rb @@ -33,15 +33,24 @@ def execute_with_arproxy(sql, name=nil, **kwargs) ::Arproxy.proxy_chain.connection = self ::Arproxy.proxy_chain.head.execute sql, name, **kwargs end - alias_method :execute_without_arproxy, :execute - alias_method :execute, :execute_with_arproxy + if private_method_defined?(:raw_execute) + alias_method :execute_without_arproxy, :raw_execute + alias_method :raw_execute, :execute_with_arproxy + else + alias_method :execute_without_arproxy, :execute + alias_method :execute, :execute_with_arproxy + end ::Arproxy.logger.debug("Arproxy: Enabled") end end def disable! @config.adapter_class.class_eval do - alias_method :execute, :execute_without_arproxy + if private_method_defined?(:raw_execute) + alias_method :raw_execute, :execute_without_arproxy + else + alias_method :execute, :execute_without_arproxy + end ::Arproxy.logger.debug("Arproxy: Disabled") end end