dynamini 2.2.6 → 2.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -7
- data/README.md +3 -1
- data/dynamini.gemspec +1 -1
- data/lib/dynamini/batch_operations.rb +6 -0
- data/lib/dynamini/test_client.rb +11 -5
- data/spec/dynamini/batch_operations_spec.rb +16 -0
- data/spec/dynamini/test_client_spec.rb +23 -0
- 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: ddc95867e816efc542b04dbcc3a7395fa0473fb1
|
4
|
+
data.tar.gz: 5a0c4e0dfd2610a65bc14d6dfc7ad1d10e86be6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 237fca68528d577f3649de7822263768be8168b63b759f8d86494e6aeea11feafa5d2d3883cfb8d6df1856916af26f4fcddce5a62d768be88d7fc9cbe6ea2f24
|
7
|
+
data.tar.gz: 0b86c52d1897331eb6dcfa078774bf853252ee2bd05cf64d99438fb045bcd637bb88bf899485479070d21d1365e885b347e4793550406c0a0db711e5f144af55
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamini (2.2.
|
4
|
+
dynamini (2.2.6)
|
5
5
|
activemodel (>= 3, < 5.0)
|
6
6
|
aws-sdk (~> 2)
|
7
7
|
|
@@ -17,12 +17,12 @@ GEM
|
|
17
17
|
minitest (~> 5.1)
|
18
18
|
thread_safe (~> 0.3, >= 0.3.4)
|
19
19
|
tzinfo (~> 1.1)
|
20
|
-
aws-sdk (2.2.
|
21
|
-
aws-sdk-resources (= 2.2.
|
22
|
-
aws-sdk-core (2.2.
|
20
|
+
aws-sdk (2.2.37)
|
21
|
+
aws-sdk-resources (= 2.2.37)
|
22
|
+
aws-sdk-core (2.2.37)
|
23
23
|
jmespath (~> 1.0)
|
24
|
-
aws-sdk-resources (2.2.
|
25
|
-
aws-sdk-core (= 2.2.
|
24
|
+
aws-sdk-resources (2.2.37)
|
25
|
+
aws-sdk-core (= 2.2.37)
|
26
26
|
builder (3.2.2)
|
27
27
|
coderay (1.1.0)
|
28
28
|
diff-lcs (1.2.5)
|
@@ -49,8 +49,10 @@ GEM
|
|
49
49
|
guard (>= 2.0.0)
|
50
50
|
guard-compat (~> 1.0)
|
51
51
|
i18n (0.7.0)
|
52
|
-
jmespath (1.
|
52
|
+
jmespath (1.2.4)
|
53
|
+
json_pure (>= 1.8.1)
|
53
54
|
json (1.8.3)
|
55
|
+
json_pure (1.8.3)
|
54
56
|
listen (3.0.3)
|
55
57
|
rb-fsevent (>= 0.9.3)
|
56
58
|
rb-inotify (>= 0.9)
|
@@ -99,3 +101,6 @@ DEPENDENCIES
|
|
99
101
|
guard-shell
|
100
102
|
pry (~> 0)
|
101
103
|
rspec (~> 3)
|
104
|
+
|
105
|
+
BUNDLED WITH
|
106
|
+
1.11.2
|
data/README.md
CHANGED
@@ -187,7 +187,9 @@ Vehicle.find('H3LLO').stuff
|
|
187
187
|
> ['wheel', 'brakes', BigDecimal(5)]
|
188
188
|
```
|
189
189
|
|
190
|
-
Please note that changing arrays in place using mutator methods like << or map! will not record a change to the object.
|
190
|
+
Please note that changing arrays in place using mutator methods like << or map! will not record a change to the object.
|
191
|
+
|
192
|
+
If you want to make changes like this, either clone it then use the assignment operator (e.g. model.array = model.array.dup << 'foo') or call model.mark(:attribute) after mutation and before saving to force Dynamini to write the change.
|
191
193
|
|
192
194
|
## Testing
|
193
195
|
We've included an optional in-memory test client, so you don't necessarily have to connect to a real Dynamo instance when running tests. You could also use this in your development environment if you don't have a real Dynamo instance yet, but the data saved to it won't persist through a server restart.
|
data/dynamini.gemspec
CHANGED
@@ -41,6 +41,12 @@ module Dynamini
|
|
41
41
|
client.batch_write_item(request_options)
|
42
42
|
end
|
43
43
|
|
44
|
+
def batch_delete(ids)
|
45
|
+
requests = ids.map{|id| { delete_request: { key: { hash_key => id } } } }
|
46
|
+
options = { request_items: { table_name => requests } }
|
47
|
+
client.batch_write_item(options)
|
48
|
+
end
|
49
|
+
|
44
50
|
private
|
45
51
|
|
46
52
|
def dynamo_batch_get(key_struct)
|
data/lib/dynamini/test_client.rb
CHANGED
@@ -86,11 +86,17 @@ module Dynamini
|
|
86
86
|
|
87
87
|
# TODO add range key support
|
88
88
|
def batch_write_item(request_options)
|
89
|
-
request_options[:request_items].each do |table_name,
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
request_options[:request_items].each do |table_name, requests|
|
90
|
+
requests.each do |request_hash|
|
91
|
+
if request_hash[:put_request]
|
92
|
+
item = request_hash[:put_request][:item]
|
93
|
+
key = item[hash_key_attr.to_s]
|
94
|
+
get_table(table_name)[key] = item
|
95
|
+
else
|
96
|
+
item = request_hash[:delete_request][:key]
|
97
|
+
id = item[hash_key_attr]
|
98
|
+
get_table(table_name).delete(id)
|
99
|
+
end
|
94
100
|
end
|
95
101
|
end
|
96
102
|
end
|
@@ -93,5 +93,21 @@ describe Dynamini::BatchOperations do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
describe '.batch_delete' do
|
97
|
+
let(:ids) { ['4321', '4567', '7890'] }
|
98
|
+
|
99
|
+
before do
|
100
|
+
Dynamini::Base.create(id: '4321')
|
101
|
+
Dynamini::Base.create(id: '4567')
|
102
|
+
Dynamini::Base.create(id: '7890')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should delete all items in collection to the database' do
|
106
|
+
subject.batch_delete(ids)
|
107
|
+
expect{ Dynamini::Base.find('4321') }.to raise_error(RuntimeError)
|
108
|
+
expect{ Dynamini::Base.find('4567') }.to raise_error(RuntimeError)
|
109
|
+
expect{ Dynamini::Base.find('7890') }.to raise_error(RuntimeError)
|
110
|
+
end
|
111
|
+
end
|
96
112
|
end
|
97
113
|
|
@@ -349,6 +349,29 @@ describe Dynamini::TestClient do
|
|
349
349
|
expect(test_client.data[table_name][1]).to eq(item1)
|
350
350
|
expect(test_client.data[table_name][2]).to eq(item2)
|
351
351
|
end
|
352
|
+
|
353
|
+
context 'batch deleting' do
|
354
|
+
before do
|
355
|
+
test_client.data[table_name] = {}
|
356
|
+
test_client.data[table_name]['one'] = {name: 'item1'}
|
357
|
+
test_client.data[table_name]['two'] = {name: 'item2'}
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'should remove all items from the table' do
|
361
|
+
|
362
|
+
delete_requests = [
|
363
|
+
{delete_request: {key: {id: 'one'}}},
|
364
|
+
{delete_request: {key: {id: 'two'}}}
|
365
|
+
]
|
366
|
+
|
367
|
+
request_options = {request_items: {table_name => delete_requests}}
|
368
|
+
expect(test_client.data[table_name]['one']).to eq({name: 'item1'})
|
369
|
+
expect(test_client.data[table_name]['two']).to eq({name: 'item2'})
|
370
|
+
test_client.batch_write_item(request_options)
|
371
|
+
expect(test_client.data[table_name]['one']).to be_nil
|
372
|
+
expect(test_client.data[table_name]['two']).to be_nil
|
373
|
+
end
|
374
|
+
end
|
352
375
|
end
|
353
376
|
|
354
377
|
describe '#batch_get_item' do
|
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: 2.2.
|
4
|
+
version: 2.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Ward
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2016-
|
18
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activemodel
|