switchman 3.5.17 → 3.5.19

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: 4be6b901fa539e03de36e75c6af7411f52b8f06cf244e1b88256cab14fd1b200
4
- data.tar.gz: cc542e6d038988551e9a05a3bef165410243b8f096b1ebfdd2a2f3c9250c602d
3
+ metadata.gz: c0df62cfbd91bd2c05864fbae14ed6f7090ff31c2fe8c4d3915956604f20532f
4
+ data.tar.gz: aa2f7a2aaabb1133136df74e596336a5cbc0273d035d30fc07a55bfb597810ab
5
5
  SHA512:
6
- metadata.gz: 0b3d5610bde72b9be796c0641c844a5e2ad73f10e359fd6a9302d0046f51c300e61182e853392e7c7f36ef9631887c64368edd88be5510b15e5b3f9f77fe8685
7
- data.tar.gz: ee6fbaec2c858ec528cdab51ec88b442aa36137347312fa53e0391f4dee8491e03b37226d12d660eb16e7aa4f20a706d914e66e096e016b7706ca1c72f3834a1
6
+ metadata.gz: b805a3291f0b67e1682c3f73cb78d2aba912afb40e981260671951147af4e577d05eb00cce9849569368543e9f5c683898193dc754bf3e83cb965e4d77b00808
7
+ data.tar.gz: 9d4dd4b68faf8596e85e291e6f0f55882645ca81a9225191235ebd2ecf20cc546378ce96bcefa0149d5f4794f15e27f95dde594643ba22e561306d60c3da51a4
@@ -291,14 +291,14 @@ module Switchman
291
291
  end
292
292
 
293
293
  module AutosaveAssociation
294
- def association_foreign_key_changed?(reflection, record, key)
295
- return false if reflection.through_reflection?
294
+ if ::Rails.version < "7.1"
295
+ def association_foreign_key_changed?(reflection, record, key)
296
+ return false if reflection.through_reflection?
296
297
 
297
- # have to use send instead of _read_attribute because sharding
298
- record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key
299
- end
298
+ # have to use send instead of _read_attribute because sharding
299
+ record.has_attribute?(reflection.foreign_key) && record.send(reflection.foreign_key) != key
300
+ end
300
301
 
301
- if ::Rails.version < "7.1"
302
302
  def save_belongs_to_association(reflection)
303
303
  # this seems counter-intuitive, but the autosave code will assign to attribute bypassing switchman,
304
304
  # after reading the id attribute _without_ bypassing switchman. So we need Shard.current for the
@@ -306,6 +306,16 @@ module Switchman
306
306
  shard.activate(connection_class_for_self_for_reflection(reflection)) { super }
307
307
  end
308
308
  else
309
+ def association_foreign_key_changed?(reflection, record, key)
310
+ return false if reflection.through_reflection?
311
+
312
+ foreign_key = Array(reflection.foreign_key)
313
+ return false unless foreign_key.all? { |k| record._has_attribute?(k) }
314
+
315
+ # have to use send instead of _read_attribute because sharding
316
+ foreign_key.map { |k| record.send(k) } != Array(key)
317
+ end
318
+
309
319
  def save_belongs_to_association(reflection)
310
320
  association = association_instance_get(reflection.name)
311
321
  return unless association&.loaded? && !association.stale_target?
@@ -112,7 +112,9 @@ module Switchman
112
112
  return unless klass.integral_id?
113
113
 
114
114
  primary_key = predicates.detect do |predicate|
115
- (predicate.is_a?(::Arel::Nodes::Binary) || predicate.is_a?(::Arel::Nodes::HomogeneousIn)) &&
115
+ (predicate.is_a?(::Arel::Nodes::Equality) ||
116
+ predicate.is_a?(::Arel::Nodes::In) ||
117
+ predicate.is_a?(::Arel::Nodes::HomogeneousIn)) &&
116
118
  predicate.left.is_a?(::Arel::Attributes::Attribute) &&
117
119
  predicate.left.relation.is_a?(::Arel::Table) && predicate.left.relation.klass == klass &&
118
120
  klass.primary_key == predicate.left.name
@@ -209,7 +211,7 @@ module Switchman
209
211
  when String, Array
210
212
  values = (Hash === rest.first) ? rest.first.values : rest
211
213
 
212
- if values.grep(ActiveRecord::Relation).first
214
+ if shard_source_value != :explicit && values.grep(ActiveRecord::Relation).first
213
215
  raise "Sub-queries are not allowed as simple substitutions; " \
214
216
  "please build your relation with more structured methods so that Switchman is able to introspect it."
215
217
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = "3.5.17"
4
+ VERSION = "3.5.19"
5
5
  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: 3.5.17
4
+ version: 3.5.19
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: 2024-01-10 00:00:00.000000000 Z
13
+ date: 2024-02-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -288,6 +288,7 @@ licenses:
288
288
  - MIT
289
289
  metadata:
290
290
  rubygems_mfa_required: 'true'
291
+ source_code_uri: https://github.com/instructure/switchman
291
292
  post_install_message:
292
293
  rdoc_options: []
293
294
  require_paths: