Sha256: bf8823506cea130f746601faad2df42751fd20ca7f7b58a7ab4c44df9a47d129

Contents?: true

Size: 987 Bytes

Versions: 36

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

module GoodJob # :nodoc:
  # Extends an ActiveRecord odel to override the connection and use
  # an explicit connection that has been removed from the pool.
  module OverridableConnection
    extend ActiveSupport::Concern

    included do
      thread_cattr_accessor :_overridden_connection
    end

    class_methods do
      # Overrides the existing connection method to use the assigned connection
      # @return [ActiveRecord::ConnectionAdapters::AbstractAdapter]
      def connection
        _overridden_connection || super
      end

      # Block interface to assign the connection, yield, then unassign the connection.
      # @param conn [ActiveRecord::ConnectionAdapters::AbstractAdapter]
      # @return [void]
      def override_connection(conn)
        original_conn = _overridden_connection
        self._overridden_connection = conn
        yield
      ensure
        self._overridden_connection = original_conn
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
good_job-4.8.0 lib/good_job/overridable_connection.rb
good_job-4.7.0 lib/good_job/overridable_connection.rb
good_job-4.6.0 lib/good_job/overridable_connection.rb
good_job-4.5.1 lib/good_job/overridable_connection.rb
good_job-4.5.0 lib/good_job/overridable_connection.rb
good_job-4.4.2 lib/good_job/overridable_connection.rb
good_job-4.4.1 lib/good_job/overridable_connection.rb
good_job-4.4.0 lib/good_job/overridable_connection.rb
good_job-4.3.0 lib/good_job/overridable_connection.rb
good_job-4.2.1 lib/good_job/overridable_connection.rb
good_job-4.2.0 lib/good_job/overridable_connection.rb
good_job-4.1.1 lib/good_job/overridable_connection.rb
good_job-4.1.0 lib/good_job/overridable_connection.rb
good_job-3.99.1 lib/good_job/overridable_connection.rb
good_job-4.0.3 lib/good_job/overridable_connection.rb
good_job-4.0.2 lib/good_job/overridable_connection.rb
good_job-4.0.1 lib/good_job/overridable_connection.rb
good_job-4.0.0 lib/good_job/overridable_connection.rb
good_job-3.99.0 lib/good_job/overridable_connection.rb
good_job-3.30.1 lib/good_job/overridable_connection.rb