switch_point 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/switch_point/connection.rb +1 -1
- data/lib/switch_point/proxy.rb +3 -4
- data/lib/switch_point/version.rb +1 -1
- data/spec/models.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77687087fa3661aba6aace55de51de3f92de2e93
|
4
|
+
data.tar.gz: ec806bac134278e915188fa93d988d640b8e50ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d6a8c24fa34a4cdefd0e87786c62bc9e861beb2d848478445cb9329362b9457bfdfe06f64ad27c451a21731feddd2a7a7d70b9d4b6a361c9177701640a6a9c
|
7
|
+
data.tar.gz: 90bcacff53ac17022d2494584c564daa56942f978e30fd7c0322a93063f7a193b057d241a2837767b043bae06a6f79dd96c43fc95cfa0d3cd7232333d4d9efd4
|
data/CHANGELOG.md
CHANGED
@@ -8,7 +8,7 @@ module SwitchPoint
|
|
8
8
|
DESTRUCTIVE_METHODS.each do |method_name|
|
9
9
|
define_method(:"#{method_name}_with_switch_point") do |*args, &block|
|
10
10
|
parent_method = :"#{method_name}_without_switch_point"
|
11
|
-
if self.pool.equal?(ActiveRecord::Base.
|
11
|
+
if self.pool.equal?(ActiveRecord::Base.connection_pool)
|
12
12
|
Connection.handle_base_connection(self, parent_method, *args, &block)
|
13
13
|
else
|
14
14
|
Connection.handle_generated_connection(self, parent_method, method_name, *args, &block)
|
data/lib/switch_point/proxy.rb
CHANGED
@@ -10,7 +10,7 @@ module SwitchPoint
|
|
10
10
|
@current_name = name
|
11
11
|
AVAILABLE_MODES.each do |mode|
|
12
12
|
model = define_model(name, mode)
|
13
|
-
memorize_switch_point(name, mode, model.
|
13
|
+
memorize_switch_point(name, mode, model.connection_pool)
|
14
14
|
end
|
15
15
|
@global_mode = DEFAULT_MODE
|
16
16
|
end
|
@@ -30,10 +30,9 @@ module SwitchPoint
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def memorize_switch_point(name, mode,
|
33
|
+
def memorize_switch_point(name, mode, pool)
|
34
34
|
switch_point = { name: name, mode: mode }
|
35
|
-
pool
|
36
|
-
if pool.equal?(ActiveRecord::Base.connection.pool)
|
35
|
+
if pool.equal?(ActiveRecord::Base.connection_pool)
|
37
36
|
if mode != :writable
|
38
37
|
raise RuntimeError.new("ActiveRecord::Base's switch_points must be writable, but #{name} is #{mode}")
|
39
38
|
end
|
data/lib/switch_point/version.rb
CHANGED
data/spec/models.rb
CHANGED
@@ -73,3 +73,12 @@ ActiveRecord::Base.configurations = {
|
|
73
73
|
'default' => base.merge(database: 'default.sqlite3')
|
74
74
|
}
|
75
75
|
ActiveRecord::Base.establish_connection(:default)
|
76
|
+
|
77
|
+
# XXX: Check connection laziness
|
78
|
+
[Book, User, Note, Nanika1, ActiveRecord::Base].each do |model|
|
79
|
+
model.with_writable do
|
80
|
+
if model.connected?
|
81
|
+
raise "#{model.name} didn't establish connection lazily!"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|