acts_as_shardable 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: 682f5dff4f95776b0c2a8d19e67d7521de209bb0
4
- data.tar.gz: 9f1478defcf88c299bdba64aa6fec066c9b55bfe
3
+ metadata.gz: 3c9172b2f82fbea155128f345ecae6cab923063c
4
+ data.tar.gz: 43ad2c18cc54d981ec0950a17342c9ef67703400
5
5
  SHA512:
6
- metadata.gz: 4acf829b64e9391ded87d396a69daf4c20569850d76f51e967f6de2b8ab0acb22df8a74d42201030ac21330539838087f99ca78ba3bec3003ce1d633b6f30cb3
7
- data.tar.gz: e1cc62c238ab080f94d802443289047d674222df0f871087d926e0095222bfa0c243f696d4467161565599d6277cd4e1c14ef1671c19180ea5c2c8eab7c3df4d
6
+ metadata.gz: c4c19e21693b35e9cbdba40a4aa83986460fc459a507880f030565b18b9880feb854c43300aef0ce57bbe1a36ac313a744db84f63e34726c733ef9f242b1c484
7
+ data.tar.gz: ce68c98e2754306f54fe456e4de992ada78d5a3a6492df3769b73ba8eb7c999187fba0206f6f2143c598b70d0c53ea85f33b3e38ffbf4a40f10d1720c2ecdbba
@@ -43,7 +43,7 @@ module ActsAsShardable
43
43
  attribute_names.uniq!
44
44
 
45
45
  begin
46
- relation = self.class.base_class.sharding(is).unscoped
46
+ relation = shard.unscoped
47
47
 
48
48
  affected_rows = relation.where(
49
49
  self.class.primary_key => id,
@@ -66,7 +66,15 @@ module ActsAsShardable
66
66
  raise
67
67
  end
68
68
  else
69
- attributes_values = arel_attributes_with_values_for_update(attribute_names)
69
+ attribute_names = attributes_for_update(attribute_names)
70
+
71
+ attributes_values = {}
72
+ arel_table = shard.arel_table
73
+
74
+ attribute_names.each do |name|
75
+ attributes_values[arel_table[name]] = typecasted_attribute_value(name)
76
+ end
77
+
70
78
  if attributes_values.empty?
71
79
  0
72
80
  else
@@ -153,8 +161,21 @@ module ActsAsShardable
153
161
  end
154
162
  end
155
163
 
156
- define_method :real do
157
- self.class.sharding(self[self.class.base_class.shard_method]).find(id)
164
+ define_method :reload do |options = nil|
165
+ clear_aggregation_cache
166
+ clear_association_cache
167
+ shard.connection.clear_query_cache
168
+
169
+ fresh_object =
170
+ if options && options[:lock]
171
+ shard.unscoped { shard.lock(options[:lock]).find(id) }
172
+ else
173
+ shard.unscoped { shard.find(id) }
174
+ end
175
+
176
+ @attributes = fresh_object.instance_variable_get('@attributes')
177
+ @new_record = false
178
+ fresh_object
158
179
  end
159
180
  end
160
181
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsShardable
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_shardable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - scorix