switchman 4.2.5 → 4.3.0

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: 4676a4e97375d1094b6775fa2a10f907218bbd2cb73f365c801a698822f779a0
4
- data.tar.gz: 4f88954e9074fcd122ecbb8d965e1b16edb63c63d69fa5311f7e0a97e400c3d5
3
+ metadata.gz: 5597662d584540dd79caadc7cebd235f8a71d71f17fbbaf0395ea64b59606327
4
+ data.tar.gz: 4a648b8b3a79dd0e368e19ce44587b2d0d1201212a8ce198860d985071461318
5
5
  SHA512:
6
- metadata.gz: f043f994b2014ce1c980d6fe73a8137a5b497831bbe87592e0c3140e777d10bcbe1460216e3dcf7cc4d1c71cdbda98d3c2b0e5a6a9859f48120cbc2b9425c24f
7
- data.tar.gz: 943659f21c0c99d8b1db896009a24601a8e698f13d0b2920e3532829a1bf0b1c5a319487d766d24c47b33a975b597ec4dc57e051ee0376e4b4dc6405515e38c8
6
+ metadata.gz: 76eafbd90f13788bc0e3d0143c243abfb4e124d87bca6a4c98ada2093541e16cf7167ab2a66355003452c88ab2aa878fc8f801810d189afc77debe6f03af14f2
7
+ data.tar.gz: ca410c5e8b49018155b14b73bd01c2042a390cdecbe39502c926b449dc4e74bd6da4f143244404cccab9ff3c5e6b30bc6b6566b780d62203353c5b13828ad346
@@ -139,6 +139,32 @@ module Switchman
139
139
  self
140
140
  end
141
141
 
142
+ def build_where_clause(opts, rest = [])
143
+ opts = sanitize_forbidden_attributes(opts)
144
+
145
+ case opts
146
+ when String, Array
147
+ values = (Hash === rest.first) ? rest.first.values : rest
148
+
149
+ if shard_source_value != :explicit && values.grep(ActiveRecord::Relation).first
150
+ raise "Sub-queries are not allowed as simple substitutions; " \
151
+ "please build your relation with more structured methods so that Switchman is able to introspect it."
152
+ end
153
+
154
+ super
155
+ when Hash, ::Arel::Nodes::Node
156
+ where_clause = super
157
+
158
+ predicates = where_clause.send(:predicates)
159
+ infer_shards_from_primary_key(predicates) if shard_source_value == :implicit && shard_value.is_a?(Shard)
160
+ predicates = transpose_predicates(predicates, nil, primary_shard)
161
+ where_clause.instance_variable_set(:@predicates, predicates)
162
+ where_clause
163
+ else
164
+ super
165
+ end
166
+ end
167
+
142
168
  private
143
169
 
144
170
  def infer_shards_from_primary_key(predicates)
@@ -237,32 +263,6 @@ module Switchman
237
263
  [attribute.relation, column]
238
264
  end
239
265
 
240
- def build_where_clause(opts, rest = [])
241
- opts = sanitize_forbidden_attributes(opts)
242
-
243
- case opts
244
- when String, Array
245
- values = (Hash === rest.first) ? rest.first.values : rest
246
-
247
- if shard_source_value != :explicit && values.grep(ActiveRecord::Relation).first
248
- raise "Sub-queries are not allowed as simple substitutions; " \
249
- "please build your relation with more structured methods so that Switchman is able to introspect it."
250
- end
251
-
252
- super
253
- when Hash, ::Arel::Nodes::Node
254
- where_clause = super
255
-
256
- predicates = where_clause.send(:predicates)
257
- infer_shards_from_primary_key(predicates) if shard_source_value == :implicit && shard_value.is_a?(Shard)
258
- predicates = transpose_predicates(predicates, nil, primary_shard)
259
- where_clause.instance_variable_set(:@predicates, predicates)
260
- where_clause
261
- else
262
- super
263
- end
264
- end
265
-
266
266
  def arel_column(columns)
267
267
  connection.with_local_table_name { super }
268
268
  end
@@ -242,7 +242,7 @@ module Switchman
242
242
  end
243
243
  end.flatten
244
244
 
245
- errors = ret.select { |val| val.is_a?(Parallel::QuietExceptionWrapper) }
245
+ errors = ret.grep(Parallel::QuietExceptionWrapper)
246
246
  unless errors.empty?
247
247
  raise errors.first.exception if errors.length == 1
248
248
 
@@ -684,8 +684,8 @@ module Switchman
684
684
  if classes.empty?
685
685
  { ::ActiveRecord::Base => self }
686
686
  else
687
- classes.each_with_object({}) do |klass, h|
688
- h[klass] = self
687
+ classes.to_h do |klass|
688
+ [klass, self]
689
689
  end
690
690
  end
691
691
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = "4.2.5"
4
+ VERSION = "4.3.0"
5
5
  end
data/lib/switchman.rb CHANGED
@@ -3,21 +3,21 @@
3
3
  require "guard_rail"
4
4
  require "zeitwerk"
5
5
 
6
- class SwitchmanInflector < Zeitwerk::GemInflector
7
- def camelize(basename, abspath)
8
- if basename =~ /\Apostgresql_(.*)/
9
- "PostgreSQL" + super($1, abspath)
10
- else
11
- super
6
+ module Switchman
7
+ class Inflector < Zeitwerk::GemInflector
8
+ def camelize(basename, abspath)
9
+ if basename =~ /\Apostgresql_(.*)/
10
+ "PostgreSQL" + super($1, abspath)
11
+ else
12
+ super
13
+ end
12
14
  end
13
15
  end
14
- end
15
16
 
16
- loader = Zeitwerk::Loader.for_gem
17
- loader.inflector = SwitchmanInflector.new(__FILE__)
18
- loader.setup
17
+ loader = Zeitwerk::Loader.for_gem
18
+ loader.inflector = Inflector.new(__FILE__)
19
+ loader.setup
19
20
 
20
- module Switchman
21
21
  Deprecation = ::ActiveSupport::Deprecation.new("4.0", "Switchman")
22
22
 
23
23
  class << self
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.2.5
4
+ version: 4.3.0
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-05-28 00:00:00.000000000 Z
13
+ date: 2026-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '7.1'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '8.1'
24
+ version: '8.2'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +31,7 @@ dependencies:
31
31
  version: '7.1'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '8.1'
34
+ version: '8.2'
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: guardrail
37
37
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: '7.1'
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
- version: '8.1'
78
+ version: '8.2'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: '7.1'
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
- version: '8.1'
88
+ version: '8.2'
89
89
  description: Sharding
90
90
  email:
91
91
  - cody@instructure.com