dynamini 1.9.1 → 1.10.0

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: 356f8de542ea075c952843efbed411bbd65f223d
4
- data.tar.gz: 97f98ccc45f1e5dcf93ed8f66628cc647c1018fb
3
+ metadata.gz: 0b81e47262cde9752334d99b56bbc0b06d7ad3b2
4
+ data.tar.gz: 3026a65ee631076b6785012b4cbcebc4aa1c07cd
5
5
  SHA512:
6
- metadata.gz: 7cc1c405737dc4e50018be9b2141aab9d1af70263a929c2d18c3d274b92266b8c10feec881f5a7121a307a1f22032121020b6fca5441a9a13966d7d43315c593
7
- data.tar.gz: e8a6743e11f1fc7ff9a3cb8e17795a273b45ce0ac4cd30b9a2f0324746b68cbdbe53cd9f048cc415adf445637d8ed8470fb8bfac0db93ab000f06f3491c5ca0c
6
+ metadata.gz: 03425cecdc1791ee2bb432b418275cd28af320275c6d7ed1a9bc60d4330989ea3fcf894aad2cef706698cf10487c1ac0ff20fde7466ba6227dbdb93903cd2ed7
7
+ data.tar.gz: 1826bf61ccb602299e4a1d8a9b426384bef196a3d238b8b86f7f4301a501c89934846408d418f153b260e6486fb7e9dea5d5dd374238c23e3c5de9346d95406f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamini (1.9.1)
4
+ dynamini (1.10.0)
5
5
  activemodel (>= 3, < 5.0)
6
6
  aws-sdk (~> 2)
7
7
 
data/dynamini.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dynamini'
3
- s.version = '1.9.1'
3
+ s.version = '1.10.0'
4
4
  s.date = '2015-12-14'
5
5
  s.summary = 'DynamoDB interface'
6
6
  s.description = 'Lightweight DynamoDB interface gem designed as
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  module Dynamini
2
4
  module BatchOperations
3
5
 
@@ -13,15 +15,16 @@ module Dynamini
13
15
  end
14
16
 
15
17
  def batch_find(ids = [])
16
- return [] if ids.length < 1
18
+ return OpenStruct.new(found: [], not_found: []) if ids.length < 1
17
19
  objects = []
18
- fail StandardError, 'Batch is limited to 100 items' if ids.length > 100
19
- key_structure = ids.map { |i| {hash_key => i.to_s} }
20
- response = dynamo_batch_get(key_structure)
21
- response.responses[table_name].each do |item|
22
- objects << new(item.symbolize_keys, false)
20
+ key_structure = ids.map { |i| {hash_key => i} }
21
+ key_structure.each_slice(100) do |keys|
22
+ response = dynamo_batch_get(keys)
23
+ response.responses[table_name].each do |item|
24
+ objects << new(item.symbolize_keys, false)
25
+ end
23
26
  end
24
- objects
27
+ OpenStruct.new(found: objects, not_found: ids - objects.map(&hash_key))
25
28
  end
26
29
 
27
30
  def dynamo_batch_save(model_array)
@@ -61,6 +61,7 @@ module Dynamini
61
61
  OpenStruct.new(item: attributes_hash)
62
62
  end
63
63
 
64
+ #FIXME Add range key support
64
65
  def batch_get_item(args = {})
65
66
  responses = {}
66
67
 
@@ -68,7 +69,7 @@ module Dynamini
68
69
  responses[k] = []
69
70
  v[:keys].each do |key_hash|
70
71
  item = @data[k][key_hash.values.first]
71
- responses[k] << item
72
+ responses[k] << item unless item.nil?
72
73
  end
73
74
  end
74
75
 
@@ -52,23 +52,43 @@ describe Dynamini::BatchOperations do
52
52
  end
53
53
  context 'when requesting 0 items' do
54
54
  it 'should return an empty array' do
55
- expect(Dynamini::Base.batch_find).to eq []
55
+ expect(Dynamini::Base.batch_find.found).to eq []
56
+ expect(Dynamini::Base.batch_find.not_found).to eq []
56
57
  end
57
58
  end
58
- context 'when requesting 2 items' do
59
- it 'should return a 2-length array containing each item' do
59
+
60
+ context 'when requesting multiple items' do
61
+ let(:result) { Dynamini::Base.batch_find(%w(abcd1234 4321 foo)) }
62
+ before do
60
63
  Dynamini::Base.create(id: '4321')
61
- objects = Dynamini::Base.batch_find(['abcd1234', '4321'])
62
- expect(objects.length).to eq 2
63
- expect(objects.first.id).to eq model.id
64
- expect(objects.last.id).to eq '4321'
64
+ end
65
+
66
+ it 'should return the found items' do
67
+ expect(result.found.length).to eq 2
68
+ expect(result.found.first.id).to eq model.id
69
+ expect(result.found.last.id).to eq '4321'
70
+ end
71
+
72
+ it 'should return the hash keys of the items not found' do
73
+ expect(result.not_found).to eq(['foo'])
65
74
  end
66
75
  end
67
- context 'when requesting too many items' do
68
- it 'should raise an error' do
69
- a = []
70
- 150.times { a << 'foo' }
71
- expect { Dynamini::Base.batch_find(a) }.to raise_error StandardError
76
+
77
+ context 'when requesting over 100 items' do
78
+ let(:ids) { Array.new(50, 'foo') + Array.new(51, '4321')}
79
+ before do
80
+ Dynamini::Base.create(id: '4321')
81
+ end
82
+
83
+ it 'should call dynamo once for each 100 items' do
84
+ expect(Dynamini::Base).to receive(:dynamo_batch_get).twice.and_call_original
85
+ Dynamini::Base.batch_find(ids)
86
+ end
87
+
88
+ it 'should return the combined responses of multiple dynamo calls' do
89
+ result = Dynamini::Base.batch_find(ids)
90
+ expect(result.found.length).to eq(51)
91
+ expect(result.not_found.length).to eq(50)
72
92
  end
73
93
  end
74
94
  end
@@ -184,4 +184,21 @@ describe Dynamini::TestClient do
184
184
  expect(test_client.data[table_name][2]).to eq(item2)
185
185
  end
186
186
  end
187
+
188
+ describe '#batch_get_item' do
189
+ let(:test_client) { Dynamini::TestClient.new(:id) }
190
+
191
+ before do
192
+ test_client.data[table_name] = {}
193
+ test_client.data[table_name]['foo'] = {id: 'foo', price: 1}
194
+ end
195
+
196
+ it 'should only return the items found' do
197
+ keys = [{id: 'foo'}, {id: 'bar'}]
198
+ request = {request_items: {table_name => {keys: keys}}}
199
+ result = test_client.batch_get_item(request)
200
+ expect(result.responses[table_name].length).to eq(1)
201
+ expect(result.responses[table_name].first[:id]).to eq('foo')
202
+ end
203
+ end
187
204
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamini
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.1
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Ward