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: 276b414f42294d6b4900e923972492ae87486ece50af3ae80ae0665c912e0e89
4
- data.tar.gz: 2a097e0f0b39655d4d82f8ef789bd5ff6e9dddd169e3ff794f11d99038a14dff
3
+ metadata.gz: 5f5836ec714370d9fabf7f96cd9531d19d2f52c0b210d28939982f61dd6b8710
4
+ data.tar.gz: 1147a2aca07d28467d043ab6e92feba021ee5efdc2bae136bcfab8a86d029e02
5
5
  SHA512:
6
- metadata.gz: 7db91542ba02b866c823de9c1a3c8b907129f2f914480fe8b4d8934699a36cb7adf679d8942993f830d086894c67e2e21b3f074af13dffc23b42b9c63ac90b26
7
- data.tar.gz: 21dd28ce6e78b82456b471f1cd3b3e33cadd3b299ad7889024abd3772719c016651b3fd9deea621a7cbe235d338749baf1e26baa9011713fa57264409ceb9580
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
@@ -1,3 +1,3 @@
1
1
  module Switchman
2
- VERSION = "1.14.1"
2
+ VERSION = "1.14.2"
3
3
  end
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.1
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-06-26 00:00:00.000000000 Z
13
+ date: 2019-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties