activerecord_partitioning 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,21 +3,22 @@ require 'activerecord_partitioning/connection_pools'
|
|
3
3
|
|
4
4
|
module ActiveRecordPartitioning
|
5
5
|
module_function
|
6
|
-
def setup(key_name,
|
7
|
-
@
|
6
|
+
def setup(key_name, default_config = nil, store = {})
|
7
|
+
@default_config = default_config.try(:symbolize_keys)
|
8
8
|
new_pools = ConnectionPools.new(key_name, store)
|
9
9
|
new_pools.merge!(ActiveRecord::Base.connection_handler.connection_pools)
|
10
10
|
ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new(new_pools)
|
11
11
|
end
|
12
12
|
|
13
13
|
def reset_connection_handler
|
14
|
+
@default_config = nil
|
14
15
|
ActiveRecord::Base.connection_handler = ActiveRecord::ConnectionAdapters::ConnectionHandler.new
|
15
16
|
end
|
16
17
|
|
17
18
|
def with_connection_pool(config, &block)
|
18
19
|
self.current_connection_pool_config = config = config.symbolize_keys
|
19
20
|
if ActiveRecord::Base.connection_pool.nil?
|
20
|
-
ActiveRecord::Base.establish_connection(@
|
21
|
+
ActiveRecord::Base.establish_connection((@default_config || {}).merge(config))
|
21
22
|
end
|
22
23
|
yield if block_given?
|
23
24
|
ensure
|
@@ -25,7 +26,7 @@ module ActiveRecordPartitioning
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def current_connection_pool_config
|
28
|
-
Thread.current[:current_connection_pool_config]
|
29
|
+
Thread.current[:current_connection_pool_config] || @default_config
|
29
30
|
end
|
30
31
|
|
31
32
|
def current_connection_pool_config=(config)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_partitioning
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Xiao Li
|