dynamini 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dynamini/base.rb +33 -11
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 109ce4b83dcb67fe1efb7c9396fbfb2b73edf943
|
4
|
+
data.tar.gz: a11d91c67bde8d3e8840290321b881d8876e93c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e9af4f62032585c3ec8ab3712f079a3a2256312e7ee307a4e33f2152075e25f48dd11cfc5fd981e6ca1ec5f2466bee162faffa99dfd34e6f683ed772b02ae8
|
7
|
+
data.tar.gz: afa9bfc847326989792d6be8d1d7d64e4ca773b0d52d55187cf18419e5eaf79b983618e19576b0f873f3ee83fa409ecf0dbdadad5ed7923aa53dd821fd4e6baa
|
data/lib/dynamini/base.rb
CHANGED
@@ -19,10 +19,11 @@ module Dynamini
|
|
19
19
|
}
|
20
20
|
|
21
21
|
class << self
|
22
|
+
|
22
23
|
attr_writer :batch_write_queue, :in_memory
|
23
24
|
|
24
25
|
def table_name
|
25
|
-
@table_name
|
26
|
+
@table_name ||= name.demodulize.tableize
|
26
27
|
end
|
27
28
|
|
28
29
|
def set_table_name(name)
|
@@ -33,6 +34,10 @@ module Dynamini
|
|
33
34
|
@hash_key = key
|
34
35
|
end
|
35
36
|
|
37
|
+
def set_range_key(key)
|
38
|
+
@range_key = key
|
39
|
+
end
|
40
|
+
|
36
41
|
def handle(column, format_class, options={})
|
37
42
|
define_handled_getter(column, format_class, options)
|
38
43
|
define_handled_setter(column, format_class)
|
@@ -42,6 +47,10 @@ module Dynamini
|
|
42
47
|
@hash_key || :id
|
43
48
|
end
|
44
49
|
|
50
|
+
def range_key
|
51
|
+
@range_key
|
52
|
+
end
|
53
|
+
|
45
54
|
def in_memory
|
46
55
|
@in_memory || false
|
47
56
|
end
|
@@ -71,8 +80,9 @@ module Dynamini
|
|
71
80
|
model if model.save!(options)
|
72
81
|
end
|
73
82
|
|
74
|
-
def find(
|
75
|
-
|
83
|
+
def find(hash_value, range_value = nil)
|
84
|
+
raise "Range key can not be blank" if range_key && range_value.nil?
|
85
|
+
response = client.get_item(table_name: table_name, key: create_key_hash(hash_value, range_value))
|
76
86
|
raise 'Item not found.' unless response.item
|
77
87
|
self.new(response.item.symbolize_keys, false)
|
78
88
|
end
|
@@ -157,7 +167,7 @@ module Dynamini
|
|
157
167
|
end
|
158
168
|
|
159
169
|
def save(options = {})
|
160
|
-
@changed.empty? || valid? && trigger_save(options)
|
170
|
+
@changed.empty? || (valid? && trigger_save(options))
|
161
171
|
end
|
162
172
|
|
163
173
|
def save!(options = {})
|
@@ -182,11 +192,11 @@ module Dynamini
|
|
182
192
|
end
|
183
193
|
end
|
184
194
|
|
185
|
-
def increment!(attribute, amount=1)
|
195
|
+
def increment!(attribute, amount=1, opts = {})
|
186
196
|
if amount.is_a?(Integer) || amount.is_a?(Float)
|
187
197
|
current_value = self.send(attribute)
|
188
198
|
if current_value.nil? || current_value.is_a?(Integer) || current_value.is_a?(Float)
|
189
|
-
increment_to_dynamo(attribute, amount)
|
199
|
+
increment_to_dynamo(attribute, amount, opts)
|
190
200
|
else
|
191
201
|
raise StandardError, 'You cannot increment! a non-numeric non-nil value. If your current value is a numeric string, use :handle to autocast it as a number.'
|
192
202
|
end
|
@@ -201,7 +211,7 @@ module Dynamini
|
|
201
211
|
end
|
202
212
|
|
203
213
|
def changes
|
204
|
-
@attributes.select { |attribute| @changed.include?(attribute.to_s) && attribute != self.class.hash_key }
|
214
|
+
@attributes.select { |attribute| @changed.include?(attribute.to_s) && attribute != self.class.hash_key && attribute != self.class.range_key }
|
205
215
|
end
|
206
216
|
|
207
217
|
def changed
|
@@ -249,8 +259,12 @@ module Dynamini
|
|
249
259
|
self.class.client.delete_item(table_name: self.class.table_name, key: key)
|
250
260
|
end
|
251
261
|
|
252
|
-
def increment_to_dynamo(attribute, amount)
|
253
|
-
|
262
|
+
def increment_to_dynamo(attribute, amount, opts={})
|
263
|
+
if opts[:skip_timestamps]
|
264
|
+
self.class.client.update_item(table_name: self.class.table_name, key: key, attribute_updates: {attribute => {value: amount, action: 'ADD'}})
|
265
|
+
else
|
266
|
+
self.class.client.update_item(table_name: self.class.table_name, key: key, attribute_updates: {attribute => {value: amount, action: 'ADD'}, updated_at: {value: attributes[:updated_at], action: 'PUT'}})
|
267
|
+
end
|
254
268
|
end
|
255
269
|
|
256
270
|
def self.dynamo_batch_get(key_structure)
|
@@ -269,7 +283,15 @@ module Dynamini
|
|
269
283
|
end
|
270
284
|
|
271
285
|
def key
|
272
|
-
{self.class.hash_key => @attributes[self.class.hash_key]}
|
286
|
+
key_hash = { self.class.hash_key => @attributes[self.class.hash_key] }
|
287
|
+
key_hash[self.class.range_key] = @attributes[self.class.range_key] if self.class.range_key
|
288
|
+
key_hash
|
289
|
+
end
|
290
|
+
|
291
|
+
def self.create_key_hash(hash_value, range_value = nil)
|
292
|
+
key_hash = { self.hash_key => hash_value }
|
293
|
+
key_hash[self.range_key] = range_value if self.range_key
|
294
|
+
key_hash
|
273
295
|
end
|
274
296
|
|
275
297
|
def attribute_updates
|
@@ -352,4 +374,4 @@ module Dynamini
|
|
352
374
|
handle :updated_at, :datetime
|
353
375
|
handle :created_at, :datetime
|
354
376
|
end
|
355
|
-
end
|
377
|
+
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.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Ward
|
@@ -9,10 +9,13 @@ authors:
|
|
9
9
|
- Alishan Ladhani
|
10
10
|
- Emily Fan
|
11
11
|
- Justine Jones
|
12
|
+
- Gillian Chesnais
|
13
|
+
- Scott Chu
|
14
|
+
- Jeff Li
|
12
15
|
autorequire:
|
13
16
|
bindir: bin
|
14
17
|
cert_chain: []
|
15
|
-
date: 2015-10-
|
18
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
16
19
|
dependencies:
|
17
20
|
- !ruby/object:Gem::Dependency
|
18
21
|
name: activemodel
|
@@ -121,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
124
|
version: '0'
|
122
125
|
requirements: []
|
123
126
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.2.2
|
125
128
|
signing_key:
|
126
129
|
specification_version: 4
|
127
130
|
summary: DynamoDB interface
|