Sha256: 5b30b9a569aa35c0dd4ff4982ebf00a7624dbb7b9d0323631262d2fe8af25427
Contents?: true
Size: 870 Bytes
Versions: 8
Compression:
Stored size: 870 Bytes
Contents
module Octoshark module CurrentConnection def current_connection Thread.current[identifier] || raise(Octoshark::Error::NoCurrentConnection, "No current connection") end def current_connection? !Thread.current[identifier].nil? end def current_or_default_connection Thread.current[identifier] || ActiveRecord::Base.connection_pool.connection end def without_connection(&block) change_connection_reference(nil) do yield end end def identifier @identifier ||= "octoshark_#{object_id}" end private def change_connection_reference(connection, &block) previous_connection = Thread.current[identifier] Thread.current[identifier] = connection begin yield ensure Thread.current[identifier] = previous_connection end end end end
Version data entries
8 entries across 8 versions & 1 rubygems