dynamini 1.6.1 → 1.7.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 +4 -4
- data/lib/dynamini/base.rb +11 -7
- data/lib/dynamini/test_client.rb +52 -14
- metadata +45 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d082532041ed50461b99235e5c5c4ca8dabb25a
|
4
|
+
data.tar.gz: bf223b3a3a970d1d90721b4d496965380a8bb278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5478cabba4e740474f6a0c9738f0fa97618451e8fc0b38f9f6fb1a45f833ac932c737db268196ddf808293465819e9082cca01199beaf0a3502324071123ca8
|
7
|
+
data.tar.gz: 7294f40fd7f3cb5bb4f97161d51d41e51223fca8070e7f695cf903d9f9dd7d523e65645da15e8012ea4e1d49af25adc582af0cb227d1fbfc854feae1dee3cda0
|
data/lib/dynamini/base.rb
CHANGED
@@ -64,7 +64,7 @@ module Dynamini
|
|
64
64
|
|
65
65
|
def client
|
66
66
|
if in_memory
|
67
|
-
@client ||= Dynamini::TestClient.new(hash_key)
|
67
|
+
@client ||= Dynamini::TestClient.new(hash_key, range_key)
|
68
68
|
else
|
69
69
|
@client ||= Aws::DynamoDB::Client.new(
|
70
70
|
region: Dynamini.configuration.region,
|
@@ -91,18 +91,22 @@ module Dynamini
|
|
91
91
|
new(response.item.symbolize_keys, false)
|
92
92
|
end
|
93
93
|
|
94
|
-
def exists?(
|
95
|
-
|
94
|
+
def exists?(hash_value, range_value = nil)
|
95
|
+
fail 'Range key cannot be blank.' if range_key && range_value.nil?
|
96
|
+
|
97
|
+
r = client.get_item(table_name: table_name, key: create_key_hash(hash_value, range_value))
|
96
98
|
r.item.present?
|
97
99
|
end
|
98
100
|
|
99
|
-
def find_or_new(
|
100
|
-
fail 'Key cannot be blank.' if (
|
101
|
-
|
101
|
+
def find_or_new(hash_value, range_value = nil)
|
102
|
+
fail 'Key cannot be blank.' if (hash_value.nil? || hash_value == '')
|
103
|
+
fail 'Range key cannot be blank.' if range_key && range_value.nil?
|
104
|
+
|
105
|
+
r = client.get_item(table_name: table_name, key: create_key_hash(hash_value, range_value))
|
102
106
|
if r.item
|
103
107
|
new(r.item.symbolize_keys, false)
|
104
108
|
else
|
105
|
-
new(hash_key =>
|
109
|
+
range_key ? new(hash_key => hash_value.to_s, range_key => range_value.to_s) : new(hash_key => hash_value.to_s)
|
106
110
|
end
|
107
111
|
end
|
108
112
|
|
data/lib/dynamini/test_client.rb
CHANGED
@@ -4,30 +4,64 @@ module Dynamini
|
|
4
4
|
# In-memory database client for test purposes.
|
5
5
|
class TestClient
|
6
6
|
|
7
|
-
attr_reader :hash_key, :data
|
7
|
+
attr_reader :hash_key, :data, :range_key
|
8
8
|
|
9
|
-
def initialize(hash_key)
|
9
|
+
def initialize(hash_key, range_key=nil)
|
10
10
|
@data = {}
|
11
11
|
@hash_key = hash_key
|
12
|
+
@range_key = range_key
|
12
13
|
end
|
13
14
|
|
14
15
|
def update_item(args = {})
|
15
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
|
+
|
16
21
|
updates = flatten_attribute_updates(args).merge(
|
17
|
-
hash_key =>
|
22
|
+
hash_key => arg_hash_key_str
|
18
23
|
)
|
24
|
+
|
19
25
|
@data[table] ||= {}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
26
|
+
|
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)
|
30
|
+
|
31
|
+
@data[table][arg_hash_key_str][arg_range_key_str].merge! updates
|
32
|
+
|
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)
|
36
|
+
|
37
|
+
@data[table][arg_hash_key_str] ||= {}
|
38
|
+
@data[table][arg_hash_key_str][arg_range_key_str] = updates
|
39
|
+
|
40
|
+
#existing record for hash ONLY
|
41
|
+
elsif @data[table][arg_hash_key_str].present?
|
42
|
+
@data[table][arg_hash_key_str].merge!(updates)
|
43
|
+
|
44
|
+
#new record for hash ONLY
|
45
|
+
elsif arg_keys[hash_key].present?
|
46
|
+
@data[table][arg_hash_key_str] = updates
|
24
47
|
end
|
48
|
+
|
25
49
|
end
|
26
50
|
|
27
51
|
def get_item(args = {})
|
28
52
|
table = args[:table_name]
|
53
|
+
hash_key_value = args[:key][hash_key]
|
54
|
+
range_key_value = args[:key][range_key]
|
55
|
+
|
29
56
|
@data[table] ||= {}
|
30
|
-
|
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
|
64
|
+
|
31
65
|
item = attributes_hash.nil? ? nil : attributes_hash
|
32
66
|
OpenStruct.new(item: item)
|
33
67
|
end
|
@@ -70,14 +104,18 @@ module Dynamini
|
|
70
104
|
def flatten_attribute_updates(args = {})
|
71
105
|
attribute_hash = {}
|
72
106
|
|
73
|
-
args[:attribute_updates]
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
107
|
+
if args[:attribute_updates]
|
108
|
+
args[:attribute_updates].each do |k, v|
|
109
|
+
|
110
|
+
if v[:action] == 'ADD' && @data[args[:table_name]][args[:key][hash_key]]
|
111
|
+
# if record has been saved
|
112
|
+
attribute_hash[k] = (v[:value] + @data[args[:table_name]][args[:key][hash_key]][k].to_f)
|
113
|
+
else
|
114
|
+
attribute_hash[k] = v[:value]
|
115
|
+
end
|
79
116
|
end
|
80
117
|
end
|
118
|
+
|
81
119
|
attribute_hash
|
82
120
|
end
|
83
121
|
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: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Ward
|
@@ -15,84 +15,112 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date: 2015-10-
|
18
|
+
date: 2015-10-30 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activemodel
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
|
-
- -
|
27
|
+
- - <
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '5.0'
|
30
30
|
type: :runtime
|
31
31
|
prerelease: false
|
32
32
|
version_requirements: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - '>='
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '3'
|
37
|
-
- -
|
37
|
+
- - <
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '5.0'
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: aws-sdk
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '2'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '2'
|
54
54
|
- !ruby/object:Gem::Dependency
|
55
55
|
name: rspec
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ~>
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3'
|
61
61
|
type: :development
|
62
62
|
prerelease: false
|
63
63
|
version_requirements: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ~>
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '3'
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: pry
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ~>
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
type: :development
|
76
76
|
prerelease: false
|
77
77
|
version_requirements: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ~>
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: fuubar
|
84
84
|
requirement: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '2'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- -
|
93
|
+
- - ~>
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '2'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: guard-rspec
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: guard-shell
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
96
124
|
description: |-
|
97
125
|
Lightweight DynamoDB interface gem designed as
|
98
126
|
a drop-in replacement for ActiveRecord.
|
@@ -116,17 +144,17 @@ require_paths:
|
|
116
144
|
- lib
|
117
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
146
|
requirements:
|
119
|
-
- -
|
147
|
+
- - '>='
|
120
148
|
- !ruby/object:Gem::Version
|
121
149
|
version: '0'
|
122
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
151
|
requirements:
|
124
|
-
- -
|
152
|
+
- - '>='
|
125
153
|
- !ruby/object:Gem::Version
|
126
154
|
version: '0'
|
127
155
|
requirements: []
|
128
156
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.2.2
|
130
158
|
signing_key:
|
131
159
|
specification_version: 4
|
132
160
|
summary: DynamoDB interface
|