dynamini 2.2.7 → 2.3.0

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: ddc95867e816efc542b04dbcc3a7395fa0473fb1
4
- data.tar.gz: 5a0c4e0dfd2610a65bc14d6dfc7ad1d10e86be6c
3
+ metadata.gz: 24230e08a1cd3cc49562240f4148352717e56799
4
+ data.tar.gz: 287d2300547737027f3cdcdbc572d8ee6f8f7ef7
5
5
  SHA512:
6
- metadata.gz: 237fca68528d577f3649de7822263768be8168b63b759f8d86494e6aeea11feafa5d2d3883cfb8d6df1856916af26f4fcddce5a62d768be88d7fc9cbe6ea2f24
7
- data.tar.gz: 0b86c52d1897331eb6dcfa078774bf853252ee2bd05cf64d99438fb045bcd637bb88bf899485479070d21d1365e885b347e4793550406c0a0db711e5f144af55
6
+ metadata.gz: 05c101089941376c9fcce5fae8daac38a89decd1c4cecfa3277bc4ef7e2cff04fba0fe22cf74a27e0ee7e77d82698496336dd6514912c21836118504d9d1359f
7
+ data.tar.gz: e7b37eeb90ce567675f102d36ffec58f49618329164a8c3884c6e46ae17e4751491d78f489a2bb2e3a7d8604ebc29337b595cf1006510762b31c51045ed1dbbc
@@ -1,28 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamini (2.2.6)
4
+ dynamini (2.3.0)
5
5
  activemodel (>= 3, < 5.0)
6
6
  aws-sdk (~> 2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (4.2.5.1)
12
- activesupport (= 4.2.5.1)
11
+ activemodel (4.2.7.1)
12
+ activesupport (= 4.2.7.1)
13
13
  builder (~> 3.1)
14
- activesupport (4.2.5.1)
14
+ activesupport (4.2.7.1)
15
15
  i18n (~> 0.7)
16
16
  json (~> 1.7, >= 1.7.7)
17
17
  minitest (~> 5.1)
18
18
  thread_safe (~> 0.3, >= 0.3.4)
19
19
  tzinfo (~> 1.1)
20
- aws-sdk (2.2.37)
21
- aws-sdk-resources (= 2.2.37)
22
- aws-sdk-core (2.2.37)
20
+ aws-sdk (2.5.3)
21
+ aws-sdk-resources (= 2.5.3)
22
+ aws-sdk-core (2.5.3)
23
23
  jmespath (~> 1.0)
24
- aws-sdk-resources (2.2.37)
25
- aws-sdk-core (= 2.2.37)
24
+ aws-sdk-resources (2.5.3)
25
+ aws-sdk-core (= 2.5.3)
26
26
  builder (3.2.2)
27
27
  coderay (1.1.0)
28
28
  diff-lcs (1.2.5)
@@ -49,16 +49,14 @@ GEM
49
49
  guard (>= 2.0.0)
50
50
  guard-compat (~> 1.0)
51
51
  i18n (0.7.0)
52
- jmespath (1.2.4)
53
- json_pure (>= 1.8.1)
52
+ jmespath (1.3.1)
54
53
  json (1.8.3)
55
- json_pure (1.8.3)
56
54
  listen (3.0.3)
57
55
  rb-fsevent (>= 0.9.3)
58
56
  rb-inotify (>= 0.9)
59
57
  lumberjack (1.0.9)
60
58
  method_source (0.8.2)
61
- minitest (5.8.4)
59
+ minitest (5.9.0)
62
60
  nenv (0.2.0)
63
61
  notiffany (0.0.8)
64
62
  nenv (~> 0.1)
@@ -103,4 +101,4 @@ DEPENDENCIES
103
101
  rspec (~> 3)
104
102
 
105
103
  BUNDLED WITH
106
- 1.11.2
104
+ 1.12.5
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dynamini'
3
- s.version = '2.2.7'
3
+ s.version = '2.3.0'
4
4
  s.summary = 'DynamoDB interface'
5
5
  s.description = 'Lightweight DynamoDB interface gem designed as
6
6
  a drop-in replacement for ActiveRecord.
@@ -0,0 +1,43 @@
1
+ module Dynamini
2
+ module GlobalId
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def deserialize_id(id)
10
+ if self.range_key
11
+ raise 'Dynamini::GlobalId.deserialize_id requires range key. please define .deserialize_id'
12
+ end
13
+
14
+ return id
15
+ end
16
+
17
+ def find(id)
18
+ hash_value, range_value = *deserialize_id(id)
19
+
20
+ fail 'Range key cannot be blank.' if range_key && range_value.nil?
21
+ response = client.get_item(
22
+ table_name: self.table_name,
23
+ key: self.create_key_hash(hash_value, range_value)
24
+ )
25
+ raise 'Item not found.' unless response.item
26
+ new(response.item.symbolize_keys, false)
27
+ end
28
+ end
29
+
30
+ def serialize_id
31
+ if self.class.range_key
32
+ raise 'Dynamini::GlobalId#serialize_id requires range key. please define #serialize_id'
33
+ end
34
+
35
+ attributes[self.class.hash_key]
36
+ end
37
+
38
+ def id
39
+ serialize_id
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'dynamini/global_id'
3
+
4
+ describe Dynamini::GlobalId do
5
+
6
+ let(:model) do
7
+ Class.new(Dynamini::Base) do
8
+ include Dynamini::GlobalId
9
+
10
+ set_table_name :test
11
+ set_hash_key :attr1
12
+ end
13
+ end
14
+
15
+ subject { model.new }
16
+
17
+ describe '#serialize_id' do
18
+ it 'returns hash key' do
19
+ id = 'this is primary id'
20
+ subject.attr1 = id
21
+ expect(subject.serialize_id).to eq(id)
22
+ end
23
+
24
+ context 'when range key is used' do
25
+ before { model.set_range_key :attr2 }
26
+
27
+ it 'raises error if not being defined' do
28
+ error_message = 'Dynamini::GlobalId#serialize_id requires range key. please define #serialize_id'
29
+ expect { subject.serialize_id }.to raise_error(error_message)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#id' do
35
+ it 'return serialized id' do
36
+ expect(subject.id).to eq(subject.serialize_id)
37
+ end
38
+ end
39
+
40
+ describe '.deserialize_id' do
41
+ it 'return the given id' do
42
+ id = "test id"
43
+ expect(model.deserialize_id(id)).to eq id
44
+ end
45
+
46
+ context 'when range key is used' do
47
+ before { model.set_range_key :attr2 }
48
+
49
+ it 'raises error if not being defined' do
50
+ error_message = 'Dynamini::GlobalId.deserialize_id requires range key. please define .deserialize_id'
51
+ expect { model.deserialize_id("id") }.to raise_error(error_message)
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '.find' do
57
+ let(:id) { 'test id' }
58
+
59
+ before do
60
+ subject.attr1 = id
61
+ subject.save
62
+ end
63
+
64
+ it 'triggers .deserialize_id with given id' do
65
+ expect(model).to receive(:deserialize_id).with(id).and_return(id)
66
+ expect(model.find(id)).to eq(subject)
67
+ end
68
+ end
69
+
70
+ 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: 2.2.7
4
+ version: 2.3.0
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-08-08 00:00:00.000000000 Z
18
+ date: 2016-08-16 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel
@@ -147,6 +147,7 @@ files:
147
147
  - lib/dynamini/client_interface.rb
148
148
  - lib/dynamini/configuration.rb
149
149
  - lib/dynamini/dirty.rb
150
+ - lib/dynamini/global_id.rb
150
151
  - lib/dynamini/increment.rb
151
152
  - lib/dynamini/querying.rb
152
153
  - lib/dynamini/test_client.rb
@@ -155,6 +156,7 @@ files:
155
156
  - spec/dynamini/base_spec.rb
156
157
  - spec/dynamini/batch_operations_spec.rb
157
158
  - spec/dynamini/dirty_spec.rb
159
+ - spec/dynamini/global_id_spec.rb
158
160
  - spec/dynamini/increment_spec.rb
159
161
  - spec/dynamini/querying_spec.rb
160
162
  - spec/dynamini/test_client_spec.rb
@@ -180,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
182
  version: '0'
181
183
  requirements: []
182
184
  rubyforge_project:
183
- rubygems_version: 2.4.6
185
+ rubygems_version: 2.4.8
184
186
  signing_key:
185
187
  specification_version: 4
186
188
  summary: DynamoDB interface
@@ -188,6 +190,7 @@ test_files:
188
190
  - spec/dynamini/base_spec.rb
189
191
  - spec/dynamini/batch_operations_spec.rb
190
192
  - spec/dynamini/dirty_spec.rb
193
+ - spec/dynamini/global_id_spec.rb
191
194
  - spec/dynamini/increment_spec.rb
192
195
  - spec/dynamini/querying_spec.rb
193
196
  - spec/dynamini/test_client_spec.rb