switchman 2.1.1 → 2.1.2

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: 53e4594468044606c5a63726359283b3ddedde69c01adbec55ed3ea66eaccaad
4
- data.tar.gz: 28b2b151c9e22a954249e9f1116e382791a20453d075fafb139609242897345e
3
+ metadata.gz: 8af8855a0c01eb0bb4b35a8e4efc2e75985ba967e1eec343b8f3b31ccffc3aa2
4
+ data.tar.gz: 18f7d47e4ebc386652a39e9d32459caeea44e7fffe2c1751dfebef8b319241e0
5
5
  SHA512:
6
- metadata.gz: b1e9930cd87320c1465d8296145ca9b390670bd71ff757873187a96ad8b2314aa621eba795ffc9e6aa74ce9ab9f4462dbcb44424d0dd1236d793d37ff0f8f78b
7
- data.tar.gz: 8827e210a74e28a6d1ee3b40efa2a2514009f4c3d825928a5e7c17ab1630b0a711dc8bf20280126624cf6560799bd3658cd1080696ab9e196524d71917add6dd
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 __temp__
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}', :__temp__
45
- undef_method :__temp__
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 __temp__
56
- Shard.local_id_for(original_#{attr_name}).first
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}', :__temp__
59
- undef_method :__temp__
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 __temp__
98
- Shard.relative_id_for(original_#{attr_name}, shard, Shard.current(#{shard_category_code_for_reflection(reflection)}))
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}', :__temp__
101
- undef_method :__temp__
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 __temp__(new_value)
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}=', :__temp__
108
- undef_method :__temp__
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 __temp__
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}', :__temp__
122
- undef_method :__temp__
132
+ alias_method '#{prefix}_#{attr_name}', :__temp_unsharded_attribute__
133
+ undef_method :__temp_unsharded_attribute__
123
134
  RUBY
124
135
  end
125
136
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Switchman
4
- VERSION = "2.1.1"
4
+ VERSION = "2.1.2"
5
5
  end
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.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 00:00:00.000000000 Z
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.2.15
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: []