toy-dynamo 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toy/dynamo/persistence.rb +3 -4
- data/lib/toy/dynamo/querying.rb +4 -0
- data/lib/toy/dynamo/table.rb +12 -15
- data/lib/toy/dynamo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d8fb485df6b884149934b10f1b21ad93f878e81
|
4
|
+
data.tar.gz: f16adea5e5212c0de9fcd8acd2491d56e3b1623a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49019ffbabacdf5bb58a77e0c6d7d074ac1a55503c61259e4954d390ba7c6eac0734c0856465426259b442b1d52da14181897039d8500181b4caa233d42ad9be
|
7
|
+
data.tar.gz: 237007ea96207888288afdfab5121b3a03421533cac41159c5f80a797664dbee3c9ebde03706012e22d53cc786cee35fb2b60a59f7e6e07a040fcdf5f85bfd54
|
@@ -10,7 +10,7 @@ module Toy
|
|
10
10
|
else
|
11
11
|
attributes_to_persist = self.class.persisted_attributes.select { |a|
|
12
12
|
# Persist changed attributes and always the range key if applicable (for lookup)
|
13
|
-
self.changed_attributes.keys.include?(a.name) || (self.class.dynamo_table.range_keys && self.class.dynamo_table.range_keys.find{|k| k[:primary_range_key]}[:attribute_name] == a.name)
|
13
|
+
self.changed_attributes.keys.include?(a.name) || (self.class.dynamo_table.range_keys && (primary_range_key = self.class.dynamo_table.range_keys.find{|k| k[:primary_range_key]}) && primary_range_key[:attribute_name] == a.name)
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
@@ -28,9 +28,8 @@ module Toy
|
|
28
28
|
def delete
|
29
29
|
@_destroyed = true
|
30
30
|
options = {}
|
31
|
-
if self.class.dynamo_table.range_keys
|
32
|
-
|
33
|
-
options[:range_value] = read_attribute(range_key[:attribute_name])
|
31
|
+
if self.class.dynamo_table.range_keys && primary_range_key = self.class.dynamo_table.range_keys.find{|k| k[:primary_range_key]}
|
32
|
+
options[:range_value] = read_attribute(primary_range_key[:attribute_name])
|
34
33
|
end
|
35
34
|
adapter.delete(persisted_id, options)
|
36
35
|
end
|
data/lib/toy/dynamo/querying.rb
CHANGED
data/lib/toy/dynamo/table.rb
CHANGED
@@ -212,7 +212,7 @@ module Toy
|
|
212
212
|
if options[:select].is_a?(Array)
|
213
213
|
attrs_to_select = [options[:select].map(&:to_s)].flatten
|
214
214
|
attrs_to_select << @hash_key[:attribute_name]
|
215
|
-
attrs_to_select << @range_keys.find{|k| k[:primary_range_key] }
|
215
|
+
attrs_to_select << primary_range_key[:attribute_name] if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key] }
|
216
216
|
query_request.merge!({
|
217
217
|
:select => QUERY_SELECT[:specific],
|
218
218
|
:attributes_to_get => attrs_to_select.uniq
|
@@ -244,11 +244,10 @@ module Toy
|
|
244
244
|
end
|
245
245
|
raise ArgumentError, "every key must include a :hash_value" if hash_value.blank?
|
246
246
|
key_request[@hash_key[:attribute_name]] = { @hash_key[:attribute_type] => hash_value.to_s }
|
247
|
-
if @range_keys.present?
|
247
|
+
if @range_keys.present? && primary_range_key = @range_keys.find{|k| k[:primary_range_key] }
|
248
248
|
range_value = k[:range_value]
|
249
249
|
raise ArgumentError, "every key must include a :range_value" if range_value.blank?
|
250
|
-
|
251
|
-
key_request[range_key[:attribute_name]] = { range_key[:attribute_type] => range_value.to_s }
|
250
|
+
key_request[primary_range_key[:attribute_name]] = { primary_range_key[:attribute_type] => range_value.to_s }
|
252
251
|
end
|
253
252
|
keys_request << key_request
|
254
253
|
end
|
@@ -275,19 +274,18 @@ module Toy
|
|
275
274
|
@hash_key[:attribute_type] => hash_key_value.to_s
|
276
275
|
}
|
277
276
|
}
|
278
|
-
if @range_keys
|
279
|
-
|
280
|
-
range_key_value = attributes[range_key[:attribute_name]]
|
277
|
+
if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key]}
|
278
|
+
range_key_value = attributes[primary_range_key[:attribute_name]]
|
281
279
|
raise ArgumentError, "range_key was not provided to the write command" if range_key_value.blank?
|
282
280
|
key_request.merge!({
|
283
|
-
|
284
|
-
|
281
|
+
primary_range_key[:attribute_name] => {
|
282
|
+
primary_range_key[:attribute_type] => primary_range_key.to_s
|
285
283
|
}
|
286
284
|
})
|
287
285
|
end
|
288
286
|
attrs_to_update = {}
|
289
287
|
attributes.each_pair do |k,v|
|
290
|
-
next if
|
288
|
+
next if primary_range_key && k == primary_range_key[:attribute_name]
|
291
289
|
if v.blank?
|
292
290
|
attrs_to_update.merge!({ k => { :action => "DELETE" } })
|
293
291
|
else
|
@@ -329,12 +327,11 @@ module Toy
|
|
329
327
|
@hash_key[:attribute_type] => hash_key_value.to_s
|
330
328
|
}
|
331
329
|
}
|
332
|
-
if @range_keys
|
333
|
-
range_key = @range_keys.find{|k| k[:primary_range_key]}
|
330
|
+
if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key]}
|
334
331
|
raise ArgumentError, "range_key was not provided to the delete_item command" if options[:range_value].blank?
|
335
332
|
key_request.merge!({
|
336
|
-
|
337
|
-
|
333
|
+
primary_range_key[:attribute_name] => {
|
334
|
+
primary_range_key[:attribute_type] => options[:range_value].to_s
|
338
335
|
}
|
339
336
|
})
|
340
337
|
end
|
@@ -383,7 +380,7 @@ module Toy
|
|
383
380
|
if options[:select].is_a?(Array)
|
384
381
|
attrs_to_select = [options[:select].map(&:to_s)].flatten
|
385
382
|
attrs_to_select << @hash_key[:attribute_name]
|
386
|
-
attrs_to_select << @range_keys.find{|k| k[:primary_range_key] }
|
383
|
+
attrs_to_select << primary_range_key[:attribute_name] if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key] }
|
387
384
|
scan_request.merge!({
|
388
385
|
:select => QUERY_SELECT[:specific],
|
389
386
|
:attributes_to_get => attrs_to_select.uniq
|
data/lib/toy/dynamo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toy-dynamo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cary Dunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|