dynamini 1.7.5 → 1.7.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dynamini/test_client.rb +41 -46
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d4b13372c015a7e191e88361d9b9ea0568ac70d
4
- data.tar.gz: 83afd9ecb74c668480cb0665fdd4d13686054625
3
+ metadata.gz: 1727f60201fa441d0e568f95a23efb08a0df1f37
4
+ data.tar.gz: 07e1b0f75e2c7393e729fd5d617060f74bca3390
5
5
  SHA512:
6
- metadata.gz: 8d3a994dffe9fda84d9c51487198f32b92ba3910d00bfa3c094ec88573cd2210a365599286ff946104ea34471f1e271cfa3d9cf32f3fea4e3001d2052b8695a8
7
- data.tar.gz: 6bb3d9a6e5612727ce9226a96f38c7f97b873da29c0059ea296a5168372fdba5af816466b40cb6528297c1d9418daa945f46ef50f7eb700e0f9e573e690ea7e9
6
+ metadata.gz: 4548219d95dae93ac2ad42e49403254f19e30bdaf8c778bb05f40da19122246732322f9c4c7f708c099f53aad7a98df9427613cfc3009de950657375c8d3c9f2
7
+ data.tar.gz: 2c85b46246e7c15348574e2e95ad54f19e4384023eccbc1c099425d49341cf5e6a8c41eddd043c63aafa84d7db272b3d9fe4f4bee1e10d304040afdda0339cb2
@@ -4,66 +4,61 @@ module Dynamini
4
4
  # In-memory database client for test purposes.
5
5
  class TestClient
6
6
 
7
- attr_reader :hash_key, :data, :range_key
7
+ attr_reader :hash_key_attr, :data, :range_key_attr
8
8
 
9
- def initialize(hash_key, range_key=nil)
9
+ def initialize(hash_key_attr, range_key_attr = nil)
10
10
  @data = {}
11
- @hash_key = hash_key
12
- @range_key = range_key
11
+ @hash_key_attr = hash_key_attr
12
+ @range_key_attr = range_key_attr
13
13
  end
14
14
 
15
- def update_item(args = {})
16
- table = args[:table_name]
17
- arg_keys = args[:key]
18
- arg_hash_key_str = arg_keys[hash_key]
19
- arg_range_key_str = arg_keys[range_key]
20
-
21
- updates = flatten_attribute_updates(args).merge(
22
- hash_key => arg_hash_key_str
23
- )
24
-
25
- @data[table] ||= {}
15
+ def get_table(table_name)
16
+ @data[table_name] ||= {}
17
+ end
26
18
 
27
- #existing record for hash && range
28
- if @data[table][arg_hash_key_str].present? && arg_keys[hash_key].present? && @range_key.present? && arg_keys[range_key].present?
29
- updates.merge!(range_key => arg_range_key_str)
19
+ def update_item(args = {})
20
+ table = get_table(args[:table_name])
30
21
 
31
- @data[table][arg_hash_key_str][arg_range_key_str].merge! updates
22
+ keys = args[:key]
32
23
 
33
- #new record for hash & range ONLY
34
- elsif arg_keys[hash_key].present? && arg_keys[range_key].present?
35
- updates.merge!(range_key => arg_range_key_str)
24
+ hash_key_value = keys[hash_key_attr]
25
+ range_key_value = keys[range_key_attr]
36
26
 
37
- @data[table][arg_hash_key_str] ||= {}
38
- @data[table][arg_hash_key_str][arg_range_key_str] = updates
27
+ updates = flatten_attribute_updates(args).merge(
28
+ hash_key_attr => hash_key_value
29
+ )
39
30
 
40
- #existing record for hash ONLY
41
- elsif @data[table][arg_hash_key_str].present?
42
- @data[table][arg_hash_key_str].merge!(updates)
31
+ if hash_key_value
32
+ if range_key_value
33
+ updates.merge!(range_key_attr => range_key_value)
34
+ if table[hash_key_value] && table[hash_key_value][range_key_value]
35
+ table[hash_key_value][range_key_value].merge! updates
36
+ else
37
+ table[hash_key_value] ||= {}
38
+ table[hash_key_value][range_key_value] = updates
39
+ end
43
40
 
44
- #new record for hash ONLY
45
- elsif arg_keys[hash_key].present?
46
- @data[table][arg_hash_key_str] = updates
41
+ else
42
+ if table[hash_key_value]
43
+ table[hash_key_value].merge!(updates)
44
+ else
45
+ table[hash_key_value] = updates
46
+ end
47
+ end
47
48
  end
48
49
 
49
50
  end
50
51
 
51
52
  def get_item(args = {})
52
- table = args[:table_name]
53
- hash_key_value = args[:key][hash_key]
54
- range_key_value = args[:key][range_key]
53
+ table = get_table(args[:table_name])
55
54
 
56
- @data[table] ||= {}
55
+ hash_key_value = args[:key][hash_key_attr]
56
+ range_key_value = args[:key][range_key_attr]
57
57
 
58
- if hash_key_value && range_key_value
59
- attributes_hash = @data[table][hash_key_value]
60
- attributes_hash = attributes_hash[range_key_value] if attributes_hash
61
- else
62
- attributes_hash = @data[table][hash_key_value]
63
- end
58
+ attributes_hash = table[hash_key_value]
59
+ attributes_hash = attributes_hash[range_key_value] if attributes_hash && range_key_value
64
60
 
65
- item = attributes_hash.nil? ? nil : attributes_hash
66
- OpenStruct.new(item: item)
61
+ OpenStruct.new(item: attributes_hash)
67
62
  end
68
63
 
69
64
  def batch_get_item(args = {})
@@ -85,14 +80,14 @@ module Dynamini
85
80
  @data[k] ||= {}
86
81
  v.each do |request_hash|
87
82
  item = request_hash[:put_request][:item]
88
- key = item[hash_key]
83
+ key = item[hash_key_attr]
89
84
  @data[k][key] = item
90
85
  end
91
86
  end
92
87
  end
93
88
 
94
89
  def delete_item(args = {})
95
- @data[args[:table_name]].delete(args[:key][hash_key])
90
+ @data[args[:table_name]].delete(args[:key][hash_key_attr])
96
91
  end
97
92
 
98
93
  def reset
@@ -104,8 +99,8 @@ module Dynamini
104
99
  def flatten_attribute_updates(args = {})
105
100
  attribute_hash = {}
106
101
 
107
- hash_key_value = args[:key][hash_key]
108
- range_key_value = args[:key][range_key]
102
+ hash_key_value = args[:key][hash_key_attr]
103
+ range_key_value = args[:key][range_key_attr]
109
104
 
110
105
  if args[:attribute_updates]
111
106
  args[:attribute_updates].each do |k, v|
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.7.5
4
+ version: 1.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Ward