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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a081dc7fc7b298bb5a17919dc56688f9aa504d4
4
- data.tar.gz: 97616bc8ba2f9443c7915d9ea250ef5e50b0306c
3
+ metadata.gz: 4d8fb485df6b884149934b10f1b21ad93f878e81
4
+ data.tar.gz: f16adea5e5212c0de9fcd8acd2491d56e3b1623a
5
5
  SHA512:
6
- metadata.gz: c6d12a4a8cbd03bbb98f8d1ba283d28771e1896b73c9b5480ef750c3b17865c9bb75ae32f654863aa3ee023a4816b37b9f34aead2bf55f29f92802c5a8daacc9
7
- data.tar.gz: 8a345618f030321fc03c0695a35467d6e79166ba7bc22e06eb1f71079462b5d4ec882c4ab018f84b871d1d9bee9651d6d25ab579cde485b643fe9d40fe7d5069
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
- range_key = self.class.dynamo_table.range_keys.find{|k| k[:primary_range_key]}
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
@@ -126,6 +126,10 @@ module Toy
126
126
  else
127
127
  aggregated_results
128
128
  end
129
+ end # scan
130
+
131
+ def read_first(hash_value, options={})
132
+ self.read_range(hash_value, options).first
129
133
  end
130
134
 
131
135
  end # ClassMethods
@@ -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] }[:attribute_name] if @range_keys
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
- range_key = @range_keys.find{|k| k[:primary_range_key] }
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
- range_key = @range_keys.find{|k| k[:primary_range_key]}
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
- range_key[:attribute_name] => {
284
- range_key[:attribute_type] => range_key_value.to_s
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 @range_keys && k == range_key[:attribute_name]
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
- range_key[:attribute_name] => {
337
- range_key[:attribute_type] => options[:range_value].to_s
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] }[:attribute_name] if @range_keys
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
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Dynamo
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.5"
4
4
  end
5
5
  end
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
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-20 00:00:00.000000000 Z
11
+ date: 2013-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler