switchman 2.1.1 → 2.1.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 +4 -4
- data/lib/switchman/active_record/attribute_methods.rb +28 -17
- data/lib/switchman/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8af8855a0c01eb0bb4b35a8e4efc2e75985ba967e1eec343b8f3b31ccffc3aa2
|
4
|
+
data.tar.gz: 18f7d47e4ebc386652a39e9d32459caeea44e7fffe2c1751dfebef8b319241e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ba8fa917299342a8d4c48048d9bb5454d7d9768a788d32905addffd105f7fffe57b90f977084fcb15c20ff0cdf24adf515d695f839a1bd5c42cd481795d7c0c
|
7
|
+
data.tar.gz: 3eea73f64b92f8bb826fa4f27b4048ec156b69c0c668386f261f51ee4ffa8b63a554be9d32180cbea3cdd3d066e2ca3801561570534f7a5c25511a8437ee6b93
|
@@ -38,11 +38,15 @@ module Switchman
|
|
38
38
|
def define_method_global_attribute(attr_name)
|
39
39
|
if sharded_column?(attr_name)
|
40
40
|
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
41
|
-
def
|
41
|
+
def __temp_global_attribute__
|
42
|
+
raw_value = original_#{attr_name}
|
43
|
+
return nil if raw_value.nil?
|
44
|
+
return raw_value if raw_value > Shard::IDS_PER_SHARD
|
45
|
+
|
42
46
|
Shard.global_id_for(original_#{attr_name}, shard)
|
43
47
|
end
|
44
|
-
alias_method 'global_#{attr_name}', :
|
45
|
-
undef_method :
|
48
|
+
alias_method 'global_#{attr_name}', :__temp_global_attribute__
|
49
|
+
undef_method :__temp_global_attribute__
|
46
50
|
RUBY
|
47
51
|
else
|
48
52
|
define_method_unsharded_column(attr_name, 'global')
|
@@ -52,11 +56,13 @@ module Switchman
|
|
52
56
|
def define_method_local_attribute(attr_name)
|
53
57
|
if sharded_column?(attr_name)
|
54
58
|
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
55
|
-
def
|
56
|
-
|
59
|
+
def __temp_local_attribute__
|
60
|
+
raw_value = original_#{attr_name}
|
61
|
+
return nil if raw_value.nil?
|
62
|
+
return raw_value % Shard::IDS_PER_SHARD
|
57
63
|
end
|
58
|
-
alias_method 'local_#{attr_name}', :
|
59
|
-
undef_method :
|
64
|
+
alias_method 'local_#{attr_name}', :__temp_local_attribute__
|
65
|
+
undef_method :__temp_local_attribute__
|
60
66
|
RUBY
|
61
67
|
else
|
62
68
|
define_method_unsharded_column(attr_name, 'local')
|
@@ -94,18 +100,23 @@ module Switchman
|
|
94
100
|
# rename the original method to original_
|
95
101
|
alias_method 'original_#{attr_name}', '#{attr_name}'
|
96
102
|
# and replace with one that transposes the id
|
97
|
-
def
|
98
|
-
|
103
|
+
def __temp_relative_attribute__
|
104
|
+
raw_value = original_#{attr_name}
|
105
|
+
return nil if raw_value.nil?
|
106
|
+
current_shard = Shard.current(#{shard_category_code_for_reflection(reflection)})
|
107
|
+
return raw_value if shard == current_shard && raw_value < Shard::IDS_PER_SHARD
|
108
|
+
|
109
|
+
Shard.relative_id_for(raw_value, shard, current_shard)
|
99
110
|
end
|
100
|
-
alias_method '#{attr_name}', :
|
101
|
-
undef_method :
|
111
|
+
alias_method '#{attr_name}', :__temp_relative_attribute__
|
112
|
+
undef_method :__temp_relative_attribute__
|
102
113
|
|
103
114
|
alias_method 'original_#{attr_name}=', '#{attr_name}='
|
104
|
-
def
|
115
|
+
def __temp_relative_attribute_assignment__(new_value)
|
105
116
|
self.original_#{attr_name} = Shard.relative_id_for(new_value, Shard.current(#{shard_category_code_for_reflection(reflection)}), shard)
|
106
117
|
end
|
107
|
-
alias_method '#{attr_name}=', :
|
108
|
-
undef_method :
|
118
|
+
alias_method '#{attr_name}=', :__temp_relative_attribute_assignment__
|
119
|
+
undef_method :__temp_relative_attribute_assignment__
|
109
120
|
RUBY
|
110
121
|
else
|
111
122
|
define_method_unsharded_column(attr_name, 'global')
|
@@ -115,11 +126,11 @@ module Switchman
|
|
115
126
|
def define_method_unsharded_column(attr_name, prefix)
|
116
127
|
return if columns_hash["#{prefix}_#{attr_name}"]
|
117
128
|
generated_attribute_methods.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
118
|
-
def
|
129
|
+
def __temp_unsharded_attribute__
|
119
130
|
raise NoMethodError, "undefined method `#{prefix}_#{attr_name}'; are you missing an association?"
|
120
131
|
end
|
121
|
-
alias_method '#{prefix}_#{attr_name}', :
|
122
|
-
undef_method :
|
132
|
+
alias_method '#{prefix}_#{attr_name}', :__temp_unsharded_attribute__
|
133
|
+
undef_method :__temp_unsharded_attribute__
|
123
134
|
RUBY
|
124
135
|
end
|
125
136
|
end
|
data/lib/switchman/version.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switchman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
- James Williams
|
9
9
|
- Jacob Fugal
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-07-
|
13
|
+
date: 2021-07-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|
@@ -257,7 +257,7 @@ homepage: http://www.instructure.com/
|
|
257
257
|
licenses:
|
258
258
|
- MIT
|
259
259
|
metadata: {}
|
260
|
-
post_install_message:
|
260
|
+
post_install_message:
|
261
261
|
rdoc_options: []
|
262
262
|
require_paths:
|
263
263
|
- lib
|
@@ -272,8 +272,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
272
|
- !ruby/object:Gem::Version
|
273
273
|
version: '0'
|
274
274
|
requirements: []
|
275
|
-
rubygems_version: 3.
|
276
|
-
signing_key:
|
275
|
+
rubygems_version: 3.0.3
|
276
|
+
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Rails sharding magic
|
279
279
|
test_files: []
|