dynamini 2.6.3 → 2.6.4

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: 7075482c77f8b6cec60de580a672fed23b646f51
4
- data.tar.gz: 03b4480b94b8e8c312885339d06ed86fd59687ad
3
+ metadata.gz: aeef2ffc6acac0bce16107fb9ec281db9509bcb2
4
+ data.tar.gz: c0757f84ebc577b1ea555c61ded01733acb2ee9a
5
5
  SHA512:
6
- metadata.gz: 49a1fff7890939d2cd39c8fb756c29cfd1c852155e90efa797f659d8488b26e720eedd7da0521734a047bb5e9f0ebf7e8c10cd090f8d2bed52337b55a1575b11
7
- data.tar.gz: 1e0ece3e30f4c3d7acbc10a6f6a5ecf814f3b09efc4542776cc180c40a2c2e83a2f39fa33f9d3845f3a49155411fdd65e3282d287a47d786c2ae11111aa7c08d
6
+ metadata.gz: b9fbb688330e9ad1f1c0330f6f45e0e04eff3e2a9524d99d7e3602b2e232fb548e4b5056d14862099206c6cd77a628f26bcc71008f87a8d406d45f66a8652c4f
7
+ data.tar.gz: a610af70e44ce47b7cec2c80ee927300a9537ee85f52091342888280fce09b1c829b6f8ae3f3116fe3a1903964375bc56702991d8fb13b981063e1c22e6dce90
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamini (2.6.3)
4
+ dynamini (2.6.4)
5
5
  activemodel (>= 3, < 5.0)
6
6
  aws-sdk (~> 2)
7
7
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'dynamini'
3
- s.version = '2.6.3'
3
+ s.version = '2.6.4'
4
4
  s.summary = 'DynamoDB interface'
5
5
  s.description = 'Lightweight DynamoDB interface gem designed as
6
6
  a drop-in replacement for ActiveRecord.
@@ -5,6 +5,7 @@ require_relative 'dirty'
5
5
  require_relative 'increment'
6
6
  require_relative 'type_handler'
7
7
  require_relative 'adder'
8
+ require_relative 'errors'
8
9
 
9
10
  module Dynamini
10
11
  # Core db interface class.
@@ -19,7 +20,6 @@ module Dynamini
19
20
  include Dynamini::TypeHandler
20
21
  include Dynamini::Adder
21
22
 
22
-
23
23
  attr_reader :attributes
24
24
  class_attribute :handles
25
25
 
@@ -114,7 +114,6 @@ module Dynamini
114
114
 
115
115
  def save!(options = {})
116
116
  run_callbacks :save do
117
-
118
117
  options[:validate] = true if options[:validate].nil?
119
118
 
120
119
  unless @changes.empty?
@@ -0,0 +1,4 @@
1
+ module Dynamini
2
+ class RecordNotFound < StandardError
3
+ end
4
+ end
@@ -5,13 +5,19 @@ module Dynamini
5
5
  def find(hash_value, range_value = nil)
6
6
  fail 'Range key cannot be blank.' if range_key && range_value.nil?
7
7
  response = client.get_item(table_name: table_name, key: create_key_hash(hash_value, range_value))
8
- raise 'Item not found.' unless response.item
8
+
9
+ unless response.item
10
+ error_msg = "Couldn't find #{self} with '#{hash_key}'=#{hash_value}"
11
+ error_msg += " and '#{range_key}'=#{range_value}" if range_value
12
+ raise Dynamini::RecordNotFound, error_msg
13
+ end
14
+
9
15
  new(response.item.symbolize_keys, false)
10
16
  end
11
17
 
12
18
  def find_or_nil(hash_value, range_value = nil)
13
19
  find(hash_value, range_value)
14
- rescue RuntimeError
20
+ rescue Dynamini::RecordNotFound
15
21
  nil
16
22
  end
17
23
 
@@ -25,7 +31,6 @@ module Dynamini
25
31
  def find_or_new(hash_value, range_value = nil)
26
32
  validate_query_values(hash_value, range_value)
27
33
 
28
-
29
34
  r = client.get_item(table_name: table_name, key: create_key_hash(hash_value, range_value))
30
35
  if r.item
31
36
  new(r.item.symbolize_keys, false)
@@ -108,4 +113,4 @@ module Dynamini
108
113
  fail 'Range key cannot be blank.' if range_key && range_value.nil?
109
114
  end
110
115
  end
111
- end
116
+ end
@@ -256,7 +256,7 @@ describe Dynamini::Base do
256
256
  context 'when the item exists in the DB' do
257
257
  it 'should delete the item and return the item' do
258
258
  expect(model.delete).to eq(model)
259
- expect { Dynamini::Base.find(model.id) }.to raise_error ('Item not found.')
259
+ expect { Dynamini::Base.find(model.id) }.to raise_error Dynamini::RecordNotFound
260
260
  end
261
261
  end
262
262
  context 'when the item does not exist in the DB' do
@@ -104,9 +104,9 @@ describe Dynamini::BatchOperations do
104
104
 
105
105
  it 'should delete all items in collection to the database' do
106
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)
107
+ expect{ Dynamini::Base.find('4321') }.to raise_error(Dynamini::RecordNotFound)
108
+ expect{ Dynamini::Base.find('4567') }.to raise_error(Dynamini::RecordNotFound)
109
+ expect{ Dynamini::Base.find('7890') }.to raise_error(Dynamini::RecordNotFound)
110
110
  end
111
111
  end
112
112
  end
@@ -37,7 +37,13 @@ describe Dynamini::Querying do
37
37
 
38
38
  context 'when the object does not exist' do
39
39
  it 'should raise an error' do
40
- expect { Dynamini::Base.find('f') }.to raise_error 'Item not found.'
40
+ expect do
41
+ Dynamini::Base.find('1')
42
+ end.to raise_error Dynamini::RecordNotFound, "Couldn't find Dynamini::Base with 'id'=1"
43
+
44
+ expect do
45
+ TestClassWithRange.find('1', '2')
46
+ end.to raise_error Dynamini::RecordNotFound, "Couldn't find TestClassWithRange with 'foo'=1 and 'bar'=2"
41
47
  end
42
48
 
43
49
  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.6.3
4
+ version: 2.6.4
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-09-27 00:00:00.000000000 Z
18
+ date: 2016-09-28 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activemodel
@@ -148,6 +148,7 @@ files:
148
148
  - lib/dynamini/client_interface.rb
149
149
  - lib/dynamini/configuration.rb
150
150
  - lib/dynamini/dirty.rb
151
+ - lib/dynamini/errors.rb
151
152
  - lib/dynamini/global_id.rb
152
153
  - lib/dynamini/increment.rb
153
154
  - lib/dynamini/querying.rb
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
185
  version: '0'
185
186
  requirements: []
186
187
  rubyforge_project:
187
- rubygems_version: 2.5.1
188
+ rubygems_version: 2.4.6
188
189
  signing_key:
189
190
  specification_version: 4
190
191
  summary: DynamoDB interface