switchman 4.3.0 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5597662d584540dd79caadc7cebd235f8a71d71f17fbbaf0395ea64b59606327
4
- data.tar.gz: 4a648b8b3a79dd0e368e19ce44587b2d0d1201212a8ce198860d985071461318
3
+ metadata.gz: 930ab408c80afadb2064fa5476f4c0cd68130f13a7dd4303bf356194d0e4bed4
4
+ data.tar.gz: 1dca68c3804bf3ea9756e2d3a9054ca830ae79bbc8977d713a9d76f3eafef8cc
5
5
  SHA512:
6
- metadata.gz: 76eafbd90f13788bc0e3d0143c243abfb4e124d87bca6a4c98ada2093541e16cf7167ab2a66355003452c88ab2aa878fc8f801810d189afc77debe6f03af14f2
7
- data.tar.gz: ca410c5e8b49018155b14b73bd01c2042a390cdecbe39502c926b449dc4e74bd6da4f143244404cccab9ff3c5e6b30bc6b6566b780d62203353c5b13828ad346
6
+ metadata.gz: 7c0a3ab18976beb94b4e9a46efb7f24e503c66363d6354946c7156e1221ffacafdc364c7bcc61205092801508ab6a329caf00c2c95592426a467b5cab86692e7
7
+ data.tar.gz: 94e9b98dfd1453eb967d02fe4a07c0cdbf4c4fdb04258da291994c9e04e3ac55c0bd4e1d214de9a0c6cfa4c10fe1b8d1476cc6509f27369f45abff1f997aadaf
@@ -135,6 +135,18 @@ module Switchman
135
135
 
136
136
  Shard.default
137
137
  end
138
+
139
+ def inherited(subclass)
140
+ super
141
+ subclass.prepend(InitializeShard)
142
+ end
143
+ end
144
+
145
+ module InitializeShard
146
+ def _run_initialize_callbacks(&)
147
+ switchman_assign_shard
148
+ super
149
+ end
138
150
  end
139
151
 
140
152
  def self.prepended(klass)
@@ -147,21 +159,7 @@ module Switchman
147
159
  klass.scope :shadow, lambda { |key = primary_key|
148
160
  where(key => QueryMethods::NonTransposingValue.new(Shard::IDS_PER_SHARD)..)
149
161
  }
150
- end
151
-
152
- def _run_initialize_callbacks
153
- @shard ||= if self.class.sharded_primary_key?
154
- Shard.shard_for(self[self.class.primary_key], Shard.current(self.class.connection_class_for_self))
155
- else
156
- Shard.current(self.class.connection_class_for_self)
157
- end
158
-
159
- @loaded_from_shard ||= Shard.current(self.class.connection_class_for_self)
160
- if shadow_record? && !Switchman.config[:writable_shadow_records]
161
- @readonly = true
162
- @readonly_from_shadow ||= true
163
- end
164
- super
162
+ klass.descendants.each { |d| d.prepend(InitializeShard) }
165
163
  end
166
164
 
167
165
  def readonly!
@@ -332,6 +330,23 @@ module Switchman
332
330
 
333
331
  private
334
332
 
333
+ def switchman_assign_shard
334
+ return if @shard && @loaded_from_shard
335
+
336
+ active_shard = Shard.current(self.class.connection_class_for_self)
337
+ @shard ||= if self.class.sharded_primary_key?
338
+ Shard.shard_for(self[self.class.primary_key], active_shard)
339
+ else
340
+ active_shard
341
+ end
342
+ @loaded_from_shard ||= active_shard
343
+
344
+ return unless shadow_record? && !Switchman.config[:writable_shadow_records]
345
+
346
+ @readonly = true
347
+ @readonly_from_shadow = true
348
+ end
349
+
335
350
  def fallback_shard
336
351
  Shard.current(self.class.connection_class_for_self) || Shard.default
337
352
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = "4.3.0"
4
+ VERSION = "4.3.2"
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: 4.3.0
4
+ version: 4.3.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: 2026-07-06 00:00:00.000000000 Z
13
+ date: 2026-08-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord