switchman 1.14.1 → 1.14.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f5836ec714370d9fabf7f96cd9531d19d2f52c0b210d28939982f61dd6b8710
|
4
|
+
data.tar.gz: 1147a2aca07d28467d043ab6e92feba021ee5efdc2bae136bcfab8a86d029e02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da283413ed625b3bfb845828c77b8ceb99beabe8742be7c02d3146bd4408ea938e6c3a7d92f59722156f2612cd9e6b296a24a9ae85bebac9970d54948c9ce0e5
|
7
|
+
data.tar.gz: 40a99fd5ab621441b112ebf16a4a7a06d0ce7d0af4b21ccfd1fc919f190b98b460c6d29bf061f81d8824dfa5c0dfa8c715adb72afe70951689190602820eed98
|
@@ -198,6 +198,13 @@ module Switchman
|
|
198
198
|
(record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key) || # have to use send instead of [] because sharding
|
199
199
|
record.attribute_changed?(reflection.foreign_key)
|
200
200
|
end
|
201
|
+
|
202
|
+
def save_belongs_to_association(reflection)
|
203
|
+
# this seems counter-intuitive, but the autosave code will assign to attribute bypassing switchman,
|
204
|
+
# after reading the id attribute _without_ bypassing switchman. So we need Shard.current for the
|
205
|
+
# category of the associated record to match Shard.current for the category of self
|
206
|
+
shard.activate(shard_category_for_reflection(reflection)) { super }
|
207
|
+
end
|
201
208
|
end
|
202
209
|
end
|
203
210
|
end
|
@@ -61,6 +61,9 @@ module Switchman
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
# see also Base#shard_category_for_reflection
|
65
|
+
# the difference being this will output static strings for the common cases, making them
|
66
|
+
# more performant
|
64
67
|
def shard_category_code_for_reflection(reflection)
|
65
68
|
if reflection
|
66
69
|
if reflection.options[:polymorphic]
|
@@ -146,6 +146,24 @@ module Switchman
|
|
146
146
|
# do this the Rails 4.2 way, so that if Shard.current != self.shard, the id gets transposed
|
147
147
|
self.class.connection.quote(id)
|
148
148
|
end
|
149
|
+
|
150
|
+
protected
|
151
|
+
|
152
|
+
# see also AttributeMethods#shard_category_code_for_reflection
|
153
|
+
def shard_category_for_reflection(reflection)
|
154
|
+
if reflection
|
155
|
+
if reflection.options[:polymorphic]
|
156
|
+
# a polymorphic association has to be discovered at runtime. This code ends up being something like
|
157
|
+
# context_type.&.constantize&.shard_category || :primary
|
158
|
+
read_attribute(reflection.foreign_type)&.constantize&.shard_category || :primary
|
159
|
+
else
|
160
|
+
# otherwise we can just return a symbol for the statically known type of the association
|
161
|
+
reflection.klass.shard_category
|
162
|
+
end
|
163
|
+
else
|
164
|
+
shard_category
|
165
|
+
end
|
166
|
+
end
|
149
167
|
end
|
150
168
|
end
|
151
169
|
end
|
data/lib/switchman/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.14.
|
4
|
+
version: 1.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-
|
13
|
+
date: 2019-07-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|