dynamini 2.2.6 → 2.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a0405b70513e4b385e3e5817bd165f3965a9da
4
- data.tar.gz: c248a81d97633dd595b6dfb3ff3f5881dee6c264
3
+ metadata.gz: ddc95867e816efc542b04dbcc3a7395fa0473fb1
4
+ data.tar.gz: 5a0c4e0dfd2610a65bc14d6dfc7ad1d10e86be6c
5
5
  SHA512:
6
- metadata.gz: ba66289642c867b5cbadbf3078a80d0d809e1210170c7b7ab41046dd6ced32a8d753596dcc919b4f7a602a9c552de0661a39d184593a9c7bc4422b16776d84c6
7
- data.tar.gz: 56d3a8b2f619e62de98763b88fec4fec50c2681a53b5086dae33865d979f7f2ac00e9d16af773d61047f6c8fb3c7c564d8625de48c2bb6394a24923ee9c38ce8
6
+ metadata.gz: 237fca68528d577f3649de7822263768be8168b63b759f8d86494e6aeea11feafa5d2d3883cfb8d6df1856916af26f4fcddce5a62d768be88d7fc9cbe6ea2f24
7
+ data.tar.gz: 0b86c52d1897331eb6dcfa078774bf853252ee2bd05cf64d99438fb045bcd637bb88bf899485479070d21d1365e885b347e4793550406c0a0db711e5f144af55
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamini (2.2.5)
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.22)
21
- aws-sdk-resources (= 2.2.22)
22
- aws-sdk-core (2.2.22)
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.22)
25
- aws-sdk-core (= 2.2.22)
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.1.3)
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. If you want to make changes like this, either use the assignment operator (e.g. model.array = model.array << 'foo') or call model.mark(:attribute) after mutation and before saving to force Dynamini to write the change.
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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dynamini'
3
- s.version = '2.2.6'
3
+ s.version = '2.2.7'
4
4
  s.summary = 'DynamoDB interface'
5
5
  s.description = 'Lightweight DynamoDB interface gem designed as
6
6
  a drop-in replacement for ActiveRecord.
@@ -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)
@@ -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, put_requests|
90
- put_requests.each do |request_hash|
91
- item = request_hash[:put_request][:item]
92
- key = item[hash_key_attr.to_s]
93
- get_table(table_name)[key] = item # not merging since real client does not support batch update
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.6
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-06-23 00:00:00.000000000 Z
18
+ date: 2016-08-08 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel