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.
- checksums.yaml +4 -4
- data/lib/dynamini/test_client.rb +41 -46
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1727f60201fa441d0e568f95a23efb08a0df1f37
|
4
|
+
data.tar.gz: 07e1b0f75e2c7393e729fd5d617060f74bca3390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4548219d95dae93ac2ad42e49403254f19e30bdaf8c778bb05f40da19122246732322f9c4c7f708c099f53aad7a98df9427613cfc3009de950657375c8d3c9f2
|
7
|
+
data.tar.gz: 2c85b46246e7c15348574e2e95ad54f19e4384023eccbc1c099425d49341cf5e6a8c41eddd043c63aafa84d7db272b3d9fe4f4bee1e10d304040afdda0339cb2
|
data/lib/dynamini/test_client.rb
CHANGED
@@ -4,66 +4,61 @@ module Dynamini
|
|
4
4
|
# In-memory database client for test purposes.
|
5
5
|
class TestClient
|
6
6
|
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :hash_key_attr, :data, :range_key_attr
|
8
8
|
|
9
|
-
def initialize(
|
9
|
+
def initialize(hash_key_attr, range_key_attr = nil)
|
10
10
|
@data = {}
|
11
|
-
@
|
12
|
-
@
|
11
|
+
@hash_key_attr = hash_key_attr
|
12
|
+
@range_key_attr = range_key_attr
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
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
|
-
|
28
|
-
|
29
|
-
updates.merge!(range_key => arg_range_key_str)
|
19
|
+
def update_item(args = {})
|
20
|
+
table = get_table(args[:table_name])
|
30
21
|
|
31
|
-
|
22
|
+
keys = args[:key]
|
32
23
|
|
33
|
-
|
34
|
-
|
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
|
-
|
38
|
-
|
27
|
+
updates = flatten_attribute_updates(args).merge(
|
28
|
+
hash_key_attr => hash_key_value
|
29
|
+
)
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
55
|
+
hash_key_value = args[:key][hash_key_attr]
|
56
|
+
range_key_value = args[:key][range_key_attr]
|
57
57
|
|
58
|
-
|
59
|
-
|
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
|
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[
|
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][
|
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][
|
108
|
-
range_key_value = args[: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|
|