toy-dynamo 0.1.5 → 0.1.6

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: 4d8fb485df6b884149934b10f1b21ad93f878e81
4
- data.tar.gz: f16adea5e5212c0de9fcd8acd2491d56e3b1623a
3
+ metadata.gz: 7a979022e1dc25fa3a291046f2740f298d841964
4
+ data.tar.gz: d26220e83e7b162126a8e80298609950bc8997fd
5
5
  SHA512:
6
- metadata.gz: 49019ffbabacdf5bb58a77e0c6d7d074ac1a55503c61259e4954d390ba7c6eac0734c0856465426259b442b1d52da14181897039d8500181b4caa233d42ad9be
7
- data.tar.gz: 237007ea96207888288afdfab5121b3a03421533cac41159c5f80a797664dbee3c9ebde03706012e22d53cc786cee35fb2b60a59f7e6e07a040fcdf5f85bfd54
6
+ metadata.gz: 9b942b853e9b412acf05208360f1fa8bbbf4a0b6ba7d0f480cd1d4ab9f141cdc850f7d085538ff9af15158745b692051af76810c4fbefac1f1016667d2301fcc
7
+ data.tar.gz: 7655f959d6dd0e993427b717c482557053b9f4ccb4533d7f3de7ce5c950c0f9042516b0a28aeb7e9fee204bb4dcdb366b7295c280caebac52e61d1af1e41f3c8
@@ -0,0 +1,13 @@
1
+ module Toy
2
+ module Extensions
3
+ module Float
4
+ def to_store(value, *)
5
+ value.nil? ? nil : value.to_f
6
+ end
7
+
8
+ def from_store(value, *)
9
+ value.nil? ? nil : value.to_f
10
+ end
11
+ end
12
+ end
13
+ end
@@ -67,8 +67,8 @@ module Toy
67
67
  results = adapter.batch_read(keys, options)
68
68
  results[:responses][dynamo_table.table_schema[:table_name]].each do |result|
69
69
  attrs = Response.strip_attr_types(result)
70
- if dynamo_table.range_keys.present?
71
- (results_map[attrs[dynamo_table.hash_key[:attribute_name]]] ||= {})[attrs[dynamo_table.range_keys.find{|rk| rk[:primary_range_key] }[:attribute_name]]] = load(attrs[dynamo_table.hash_key[:attribute_name]], attrs)
70
+ if dynamo_table.range_keys.present? && primary_range_key = dynamo_table.range_keys.find{|rk| rk[:primary_range_key] }
71
+ (results_map[attrs[dynamo_table.hash_key[:attribute_name]]] ||= {})[attrs[primary_range_key[:attribute_name]]] = load(attrs[dynamo_table.hash_key[:attribute_name]], attrs)
72
72
  else
73
73
  results_map[attrs[dynamo_table.hash_key[:attribute_name]]] = load(attrs[dynamo_table.hash_key[:attribute_name]], attrs)
74
74
  end
@@ -71,6 +71,7 @@ module Toy
71
71
  @hash_key = key_schema_attr
72
72
  else
73
73
  (@range_keys ||= []) << key_schema_attr.merge(:primary_range_key => true)
74
+ @primary_range_key = key_schema_attr.merge(:primary_range_key => true)
74
75
  end
75
76
  end
76
77
 
@@ -212,7 +213,7 @@ module Toy
212
213
  if options[:select].is_a?(Array)
213
214
  attrs_to_select = [options[:select].map(&:to_s)].flatten
214
215
  attrs_to_select << @hash_key[:attribute_name]
215
- attrs_to_select << primary_range_key[:attribute_name] if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key] }
216
+ attrs_to_select << @primary_range_key[:attribute_name] if @primary_range_key
216
217
  query_request.merge!({
217
218
  :select => QUERY_SELECT[:specific],
218
219
  :attributes_to_get => attrs_to_select.uniq
@@ -236,7 +237,7 @@ module Toy
236
237
  keys_request = []
237
238
  keys.each do |k|
238
239
  key_request = {}
239
- if @range_keys.present?
240
+ if @primary_range_key
240
241
  hash_value = k[:hash_value]
241
242
  else
242
243
  raise ArgumentError, "expected keys to be in the form of ['hash key here'] for table with no range keys" if hash_value.is_a?(Hash)
@@ -244,10 +245,10 @@ module Toy
244
245
  end
245
246
  raise ArgumentError, "every key must include a :hash_value" if hash_value.blank?
246
247
  key_request[@hash_key[:attribute_name]] = { @hash_key[:attribute_type] => hash_value.to_s }
247
- if @range_keys.present? && primary_range_key = @range_keys.find{|k| k[:primary_range_key] }
248
+ if @primary_range_key
248
249
  range_value = k[:range_value]
249
250
  raise ArgumentError, "every key must include a :range_value" if range_value.blank?
250
- key_request[primary_range_key[:attribute_name]] = { primary_range_key[:attribute_type] => range_value.to_s }
251
+ key_request[@primary_range_key[:attribute_name]] = { @primary_range_key[:attribute_type] => range_value.to_s }
251
252
  end
252
253
  keys_request << key_request
253
254
  end
@@ -274,18 +275,18 @@ module Toy
274
275
  @hash_key[:attribute_type] => hash_key_value.to_s
275
276
  }
276
277
  }
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]]
278
+ if @primary_range_key
279
+ range_key_value = attributes[@primary_range_key[:attribute_name]]
279
280
  raise ArgumentError, "range_key was not provided to the write command" if range_key_value.blank?
280
281
  key_request.merge!({
281
- primary_range_key[:attribute_name] => {
282
- primary_range_key[:attribute_type] => primary_range_key.to_s
282
+ @primary_range_key[:attribute_name] => {
283
+ @primary_range_key[:attribute_type] => range_key_value.to_s
283
284
  }
284
285
  })
285
286
  end
286
287
  attrs_to_update = {}
287
288
  attributes.each_pair do |k,v|
288
- next if primary_range_key && k == primary_range_key[:attribute_name]
289
+ next if @primary_range_key && k == @primary_range_key[:attribute_name]
289
290
  if v.blank?
290
291
  attrs_to_update.merge!({ k => { :action => "DELETE" } })
291
292
  else
@@ -327,11 +328,11 @@ module Toy
327
328
  @hash_key[:attribute_type] => hash_key_value.to_s
328
329
  }
329
330
  }
330
- if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key]}
331
+ if @primary_range_key
331
332
  raise ArgumentError, "range_key was not provided to the delete_item command" if options[:range_value].blank?
332
333
  key_request.merge!({
333
- primary_range_key[:attribute_name] => {
334
- primary_range_key[:attribute_type] => options[:range_value].to_s
334
+ @primary_range_key[:attribute_name] => {
335
+ @primary_range_key[:attribute_type] => options[:range_value].to_s
335
336
  }
336
337
  })
337
338
  end
@@ -380,7 +381,7 @@ module Toy
380
381
  if options[:select].is_a?(Array)
381
382
  attrs_to_select = [options[:select].map(&:to_s)].flatten
382
383
  attrs_to_select << @hash_key[:attribute_name]
383
- attrs_to_select << primary_range_key[:attribute_name] if @range_keys && primary_range_key = @range_keys.find{|k| k[:primary_range_key] }
384
+ attrs_to_select << @primary_range_key[:attribute_name] if @primary_range_key
384
385
  scan_request.merge!({
385
386
  :select => QUERY_SELECT[:specific],
386
387
  :attributes_to_get => attrs_to_select.uniq
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Dynamo
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
data/lib/toy/dynamo.rb CHANGED
@@ -17,6 +17,7 @@ require "toy/dynamo/extensions/hash"
17
17
  require "toy/dynamo/extensions/set"
18
18
  require "toy/dynamo/extensions/time"
19
19
  require "toy/dynamo/extensions/symbol"
20
+ require "toy/dynamo/extensions/float"
20
21
 
21
22
  module Toy
22
23
  module Dynamo
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.5
4
+ version: 0.1.6
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-26 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -101,6 +101,7 @@ files:
101
101
  - lib/toy/dynamo/extensions/array.rb
102
102
  - lib/toy/dynamo/extensions/boolean.rb
103
103
  - lib/toy/dynamo/extensions/date.rb
104
+ - lib/toy/dynamo/extensions/float.rb
104
105
  - lib/toy/dynamo/extensions/hash.rb
105
106
  - lib/toy/dynamo/extensions/set.rb
106
107
  - lib/toy/dynamo/extensions/symbol.rb