Module: TestProf::ActiveRecordSharedConnection

Defined in:
lib/test_prof/recipes/active_record_shared_connection.rb

Overview

Forces ActiveRecord to use the same connection between threads

Defined Under Namespace

Modules: Connection, Ext

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/test_prof/recipes/active_record_shared_connection.rb', line 7

def connection
  @connection
end

Class Method Details

.disable!Object



13
14
15
# File 'lib/test_prof/recipes/active_record_shared_connection.rb', line 13

def disable!
  self.connection = nil
end

.enable!Object



9
10
11
# File 'lib/test_prof/recipes/active_record_shared_connection.rb', line 9

def enable!
  self.connection = ActiveRecord::Base.connection
end

.ignoreObject

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
# File 'lib/test_prof/recipes/active_record_shared_connection.rb', line 17

def ignore
  raise ArgumentError, "Block is required" unless block_given?

  @ignores ||= []

  ignores << Proc.new
end

.ignored?(config) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/test_prof/recipes/active_record_shared_connection.rb', line 25

def ignored?(config)
  !ignores.nil? && ignores.any? { |clbk| clbk.call(config) }
end