Module: Knockoff
- Defined in:
- lib/knockoff.rb,
lib/knockoff/base.rb,
lib/knockoff/error.rb,
lib/knockoff/config.rb,
lib/knockoff/version.rb,
lib/knockoff/replica_connection_pool.rb
Defined Under Namespace
Classes: Base, Config, Error, ReplicaConnectionPool
Constant Summary
collapse
- VERSION =
'1.0'.freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.enabled ⇒ Object
Returns the value of attribute enabled.
12
13
14
|
# File 'lib/knockoff.rb', line 12
def enabled
@enabled
end
|
Class Method Details
.base_transaction_depth ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/knockoff.rb', line 47
def base_transaction_depth
@base_transaction_depth ||= begin
testcase = ActiveSupport::TestCase
if defined?(testcase) &&
testcase.respond_to?(:use_transactional_fixtures) &&
testcase.try(:use_transactional_fixtures)
1
else
0
end
end
end
|
.clear_all_active_connections! ⇒ Object
26
27
28
|
# File 'lib/knockoff.rb', line 26
def clear_all_active_connections!
replica_pool.clear_all_active_connections!
end
|
.config ⇒ Object
43
44
45
|
# File 'lib/knockoff.rb', line 43
def config
@config ||= Config.new
end
|
.disconnect_all! ⇒ Object
Iterates through the replica pool and calls disconnect on each one’s connection.
31
32
33
|
# File 'lib/knockoff.rb', line 31
def disconnect_all!
replica_pool.disconnect_all_replicas!
end
|
.establish_new_connections!(new_config) ⇒ Object
Updates the config (both internal representation and the ActiveRecord::Base.configuration) with the new config, and then reconnects each replica connection in the replica pool.
38
39
40
41
|
# File 'lib/knockoff.rb', line 38
def establish_new_connections!(new_config)
config.update_replica_configs(new_config)
replica_pool.reconnect_all_replicas!
end
|
.on_primary(&block) ⇒ Object
18
19
20
|
# File 'lib/knockoff.rb', line 18
def on_primary(&block)
Base.new(:primary).run(&block)
end
|
.on_replica(&block) ⇒ Object
14
15
16
|
# File 'lib/knockoff.rb', line 14
def on_replica(&block)
Base.new(:replica).run(&block)
end
|
.replica_pool ⇒ Object
22
23
24
|
# File 'lib/knockoff.rb', line 22
def replica_pool
@replica_pool ||= ReplicaConnectionPool.new(config.replica_database_keys)
end
|