module Yrpc module Interceptors module ActiveRecord class ResetConnection def invoke if enabled? && !::ActiveRecord::Base.connection.active? ::ActiveRecord::Base.establish_connection end yield ensure ::ActiveRecord::Base.clear_active_connections! if enabled? end private ## # @return [Boolean] If AR is loaded, we can enable this hook safely # def enabled? defined?(::ActiveRecord::Base) end end end end end