Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_sqs_moniter/monkey_patches/forbid_implicit_active_record_connection_checkout.rb

Direct Known Subclasses

DeadLetter, ProcessedMessage, PublishedMessage

Class Method Summary collapse

Class Method Details

.connection_with_forbid_implicit(*args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/aws_sqs_moniter/monkey_patches/forbid_implicit_active_record_connection_checkout.rb', line 12

def connection_with_forbid_implicit(*args, &block)
  if implicit_checkout_forbidden? && !connection_handler.retrieve_connection_pool(self).active_connection?
    message = 'Implicit ActiveRecord checkout attempted when Thread :force_explicit_connections set!'

    # I want to make SURE I see this error in test output, even though
    # in some cases my code is swallowing the exception.
    $stderr.puts(message) if Rails.env.test?

    fail ImplicitConnectionForbiddenError, message
  end

  connection_without_forbid_implicit(*args, &block)
end

.forbid_implicit_checkout!Object



4
5
6
# File 'lib/aws_sqs_moniter/monkey_patches/forbid_implicit_active_record_connection_checkout.rb', line 4

def forbid_implicit_checkout!
  Thread.current[:active_record_forbid_implicit_connections] = true
end

.implicit_checkout_forbidden?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/aws_sqs_moniter/monkey_patches/forbid_implicit_active_record_connection_checkout.rb', line 8

def implicit_checkout_forbidden?
  !!Thread.current[:active_record_forbid_implicit_connections]
end