switchman 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/switchman/active_record/attribute_methods.rb +33 -26
- data/lib/switchman/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd3fc41cd455d5855db84fd49d132dca58c824dbe50e49ea4ab7c4cd0ee24d00
|
4
|
+
data.tar.gz: df1df2b43f521a5b5e424165ac167d2de351c4800db6fe50b5d83a78e8e17e16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b721c57764dc47c2da10b027b63fdeed4795c349b2dec36b0d440e98ff0294355a4bbb03d2176f30883de0b842e2f4a47f27ea2fa2f56405594f53d4a278f6c
|
7
|
+
data.tar.gz: 2729dfb39b1e3d8e3df84bcf1bd321ac39de73e552d8a6c0f15f48f6b9fdb47611a076f8e11fbcbfeb4fd8097c2e6a49a2eab7d76942af92ed769c03b1b9f7d0
|
@@ -26,10 +26,10 @@ module Switchman
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def define_attribute_methods
|
29
|
-
super
|
29
|
+
result = super
|
30
30
|
# ensure that we're using the sharded attribute method
|
31
31
|
# and not the silly one in AR::AttributeMethods::PrimaryKey
|
32
|
-
return unless sharded_column?(@primary_key)
|
32
|
+
return result unless sharded_column?(@primary_key)
|
33
33
|
|
34
34
|
class_eval(
|
35
35
|
build_sharded_getter("id",
|
@@ -41,6 +41,7 @@ module Switchman
|
|
41
41
|
class_eval(build_sharded_setter("id", @primary_key, "::#{connection_class_for_self.name}"),
|
42
42
|
__FILE__,
|
43
43
|
__LINE__)
|
44
|
+
result
|
44
45
|
end
|
45
46
|
|
46
47
|
protected
|
@@ -55,14 +56,20 @@ module Switchman
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def define_cached_method(owner, name, namespace:, as:, &block)
|
58
|
-
|
59
|
+
if ::Rails.version < "7.1.4"
|
60
|
+
# https://github.com/rails/rails/commit/a2a12fc2e3f4e6d06f81d4c74c88f8e6b3369ee6#diff-5b59ece6d9396b596f06271cec0ea726e3360911383511c49b1a66f454bfc2b6L30
|
61
|
+
# These arguments were effectively swapped in Rails 7.1.4, so previous versions need them reversed
|
62
|
+
owner.define_cached_method(as, namespace: namespace, as: name, &block)
|
63
|
+
else
|
64
|
+
owner.define_cached_method(name, namespace: namespace, as: as, &block)
|
65
|
+
end
|
59
66
|
end
|
60
67
|
|
61
|
-
def define_method_global_attribute(attr_name, owner:)
|
68
|
+
def define_method_global_attribute(attr_name, owner:, as: attr_name)
|
62
69
|
if sharded_column?(attr_name)
|
63
70
|
define_cached_method(owner,
|
64
|
-
"
|
65
|
-
as: "
|
71
|
+
"sharded_global_#{attr_name}",
|
72
|
+
as: "global_#{as}",
|
66
73
|
namespace: :switchman) do |batch|
|
67
74
|
batch << <<-RUBY
|
68
75
|
def sharded_global_#{attr_name}
|
@@ -79,11 +86,11 @@ module Switchman
|
|
79
86
|
end
|
80
87
|
end
|
81
88
|
|
82
|
-
def define_method_local_attribute(attr_name, owner:)
|
89
|
+
def define_method_local_attribute(attr_name, owner:, as: attr_name)
|
83
90
|
if sharded_column?(attr_name)
|
84
91
|
define_cached_method(owner,
|
85
|
-
"
|
86
|
-
as: "
|
92
|
+
"sharded_local_#{attr_name}",
|
93
|
+
as: "local_#{as}",
|
87
94
|
namespace: :switchman) do |batch|
|
88
95
|
batch << <<-RUBY
|
89
96
|
def sharded_local_#{attr_name}
|
@@ -122,21 +129,21 @@ module Switchman
|
|
122
129
|
end
|
123
130
|
end
|
124
131
|
|
125
|
-
def define_method_attribute(attr_name, owner:)
|
132
|
+
def define_method_attribute(attr_name, owner:, as: attr_name)
|
126
133
|
if sharded_column?(attr_name)
|
127
134
|
reflection = reflection_for_integer_attribute(attr_name)
|
128
135
|
class_name = connection_class_for_self_code_for_reflection(reflection)
|
129
136
|
safe_class_name = class_name.unpack1("h*")
|
130
137
|
define_cached_method(owner,
|
131
|
-
attr_name,
|
132
|
-
as:
|
138
|
+
"sharded_#{safe_class_name}_#{attr_name}",
|
139
|
+
as: as,
|
133
140
|
namespace: :switchman) do |batch|
|
134
141
|
batch << build_sharded_getter("sharded_#{safe_class_name}_#{attr_name}",
|
135
|
-
"original_#{
|
142
|
+
"original_#{as}",
|
136
143
|
class_name)
|
137
144
|
end
|
138
145
|
else
|
139
|
-
define_cached_method(owner,
|
146
|
+
define_cached_method(owner, "plain_#{attr_name}", as: as, namespace: :switchman) do |batch|
|
140
147
|
batch << <<-RUBY
|
141
148
|
def plain_#{attr_name}
|
142
149
|
_read_attribute("#{attr_name}") { |n| missing_attribute(n, caller) }
|
@@ -169,19 +176,19 @@ module Switchman
|
|
169
176
|
RUBY
|
170
177
|
end
|
171
178
|
|
172
|
-
def define_method_attribute=(attr_name, owner:)
|
179
|
+
def define_method_attribute=(attr_name, owner:, as: attr_name)
|
173
180
|
if sharded_column?(attr_name)
|
174
181
|
reflection = reflection_for_integer_attribute(attr_name)
|
175
182
|
class_name = connection_class_for_self_code_for_reflection(reflection)
|
176
183
|
safe_class_name = class_name.unpack1("h*")
|
177
184
|
define_cached_method(owner,
|
178
|
-
"#{attr_name}=",
|
179
|
-
as: "
|
185
|
+
"sharded_#{safe_class_name}_#{attr_name}=",
|
186
|
+
as: "#{as}=",
|
180
187
|
namespace: :switchman) do |batch|
|
181
188
|
batch << build_sharded_setter("sharded_#{safe_class_name}_#{attr_name}", attr_name, class_name)
|
182
189
|
end
|
183
190
|
else
|
184
|
-
define_cached_method(owner, "#{attr_name}=", as: "
|
191
|
+
define_cached_method(owner, "plain_#{attr_name}=", as: "#{as}=", namespace: :switchman) do |batch|
|
185
192
|
batch << <<-RUBY
|
186
193
|
def plain_#{attr_name}=(new_value)
|
187
194
|
_write_attribute('#{attr_name}', new_value)
|
@@ -199,11 +206,11 @@ module Switchman
|
|
199
206
|
RUBY
|
200
207
|
end
|
201
208
|
|
202
|
-
def define_method_original_attribute(attr_name, owner:)
|
209
|
+
def define_method_original_attribute(attr_name, owner:, as: attr_name)
|
203
210
|
if sharded_column?(attr_name)
|
204
211
|
define_cached_method(owner,
|
205
|
-
"
|
206
|
-
as: "
|
212
|
+
"sharded_original_#{attr_name}",
|
213
|
+
as: "original_#{as}",
|
207
214
|
namespace: :switchman) do |batch|
|
208
215
|
batch << <<-RUBY
|
209
216
|
def sharded_original_#{attr_name}
|
@@ -216,12 +223,12 @@ module Switchman
|
|
216
223
|
end
|
217
224
|
end
|
218
225
|
|
219
|
-
def define_method_original_attribute=(attr_name, owner:)
|
226
|
+
def define_method_original_attribute=(attr_name, owner:, as: attr_name)
|
220
227
|
return unless sharded_column?(attr_name)
|
221
228
|
|
222
229
|
define_cached_method(owner,
|
223
|
-
"
|
224
|
-
as: "
|
230
|
+
"sharded_original_#{attr_name}=",
|
231
|
+
as: "original_#{as}=",
|
225
232
|
namespace: :switchman) do |batch|
|
226
233
|
batch << <<-RUBY
|
227
234
|
def sharded_original_#{attr_name}=(new_value)
|
@@ -235,8 +242,8 @@ module Switchman
|
|
235
242
|
return if columns_hash["#{prefix}_#{attr_name}"] || attr_name == "id"
|
236
243
|
|
237
244
|
define_cached_method(owner,
|
238
|
-
"#{prefix}_#{attr_name}",
|
239
|
-
as: "
|
245
|
+
"unsharded_#{prefix}_#{attr_name}",
|
246
|
+
as: "#{prefix}_#{attr_name}",
|
240
247
|
namespace: :switchman) do |batch|
|
241
248
|
batch << <<-RUBY
|
242
249
|
def unsharded_#{prefix}_#{attr_name}
|
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: 4.0.
|
4
|
+
version: 4.0.1
|
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: 2025-02-
|
13
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|