aws-record 2.10.0 → 2.11.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/CHANGELOG.md +335 -0
- data/LICENSE +202 -0
- data/VERSION +1 -0
- data/lib/aws-record/record/attribute.rb +9 -21
- data/lib/aws-record/record/attributes.rb +68 -78
- data/lib/aws-record/record/batch.rb +13 -12
- data/lib/aws-record/record/batch_read.rb +5 -2
- data/lib/aws-record/record/batch_write.rb +1 -12
- data/lib/aws-record/record/buildable_search.rb +33 -28
- data/lib/aws-record/record/client_configuration.rb +10 -21
- data/lib/aws-record/record/dirty_tracking.rb +30 -44
- data/lib/aws-record/record/errors.rb +1 -13
- data/lib/aws-record/record/item_collection.rb +5 -16
- data/lib/aws-record/record/item_data.rb +4 -18
- data/lib/aws-record/record/item_operations.rb +86 -93
- data/lib/aws-record/record/key_attributes.rb +1 -14
- data/lib/aws-record/record/marshalers/boolean_marshaler.rb +2 -16
- data/lib/aws-record/record/marshalers/date_marshaler.rb +1 -15
- data/lib/aws-record/record/marshalers/date_time_marshaler.rb +2 -14
- data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +1 -14
- data/lib/aws-record/record/marshalers/float_marshaler.rb +3 -19
- data/lib/aws-record/record/marshalers/integer_marshaler.rb +3 -19
- data/lib/aws-record/record/marshalers/list_marshaler.rb +2 -16
- data/lib/aws-record/record/marshalers/map_marshaler.rb +2 -16
- data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +3 -16
- data/lib/aws-record/record/marshalers/string_marshaler.rb +2 -16
- data/lib/aws-record/record/marshalers/string_set_marshaler.rb +3 -16
- data/lib/aws-record/record/marshalers/time_marshaler.rb +1 -14
- data/lib/aws-record/record/model_attributes.rb +14 -35
- data/lib/aws-record/record/query.rb +7 -21
- data/lib/aws-record/record/secondary_indexes.rb +23 -42
- data/lib/aws-record/record/table_config.rb +52 -74
- data/lib/aws-record/record/table_migration.rb +43 -66
- data/lib/aws-record/record/transactions.rb +67 -38
- data/lib/aws-record/record/version.rb +2 -13
- data/lib/aws-record/record.rb +30 -49
- metadata +14 -5
@@ -1,20 +1,8 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
16
5
|
module DirtyTracking
|
17
|
-
|
18
6
|
def self.included(sub_class)
|
19
7
|
sub_class.extend(DirtyTrackingClassMethods)
|
20
8
|
end
|
@@ -37,7 +25,7 @@ module Aws
|
|
37
25
|
# @return [Boolean] +true+ if the specified attribute has any dirty changes, +false+ otherwise.
|
38
26
|
def attribute_dirty?(name)
|
39
27
|
@data.attribute_dirty?(name)
|
40
|
-
end
|
28
|
+
end
|
41
29
|
|
42
30
|
# Returns the original value of the specified attribute.
|
43
31
|
#
|
@@ -50,7 +38,7 @@ module Aws
|
|
50
38
|
#
|
51
39
|
# model.name # => 'Alex'
|
52
40
|
# model.name = 'Nick'
|
53
|
-
# model.name_was # => 'Alex'
|
41
|
+
# model.name_was # => 'Alex'
|
54
42
|
#
|
55
43
|
# @param [String, Symbol] name The name of the attribute to retrieve the original value of.
|
56
44
|
# @return [Object] The original value of the specified attribute.
|
@@ -58,8 +46,9 @@ module Aws
|
|
58
46
|
@data.attribute_was(name)
|
59
47
|
end
|
60
48
|
|
61
|
-
# Mark that an attribute is changing. This is useful in situations
|
62
|
-
#
|
49
|
+
# Mark that an attribute is changing. This is useful in situations
|
50
|
+
# where it is necessary to track that the value of an
|
51
|
+
# attribute is changing in-place.
|
63
52
|
#
|
64
53
|
# @example
|
65
54
|
# class Model
|
@@ -74,9 +63,9 @@ module Aws
|
|
74
63
|
#
|
75
64
|
# model.name << 'i'
|
76
65
|
# model.name # => 'Alexi'
|
77
|
-
#
|
78
|
-
# # The change was made in place. Since the String instance representing
|
79
|
-
# # the value of name is the same as it was originally, the change is not
|
66
|
+
#
|
67
|
+
# # The change was made in place. Since the String instance representing
|
68
|
+
# # the value of name is the same as it was originally, the change is not
|
80
69
|
# # detected.
|
81
70
|
# model.name_dirty? # => false
|
82
71
|
# model.name_was # => 'Alexi'
|
@@ -90,7 +79,7 @@ module Aws
|
|
90
79
|
# model.name_dirty? # => true
|
91
80
|
# model.name_was # => 'Alexi'
|
92
81
|
#
|
93
|
-
# @param [String, Symbol] name The name of the attribute to mark as
|
82
|
+
# @param [String, Symbol] name The name of the attribute to mark as
|
94
83
|
# changing.
|
95
84
|
def attribute_dirty!(name)
|
96
85
|
@data.attribute_dirty!(name)
|
@@ -129,7 +118,7 @@ module Aws
|
|
129
118
|
# model.name = 'Nick'
|
130
119
|
# model.dirty? # => true
|
131
120
|
#
|
132
|
-
# @return [Boolean] +true+ if any attributes have dirty changes, +false+
|
121
|
+
# @return [Boolean] +true+ if any attributes have dirty changes, +false+
|
133
122
|
# otherwise.
|
134
123
|
def dirty?
|
135
124
|
@data.dirty?
|
@@ -151,7 +140,7 @@ module Aws
|
|
151
140
|
# model.delete!
|
152
141
|
# model.persisted? # => false
|
153
142
|
#
|
154
|
-
# @return [Boolean] +true+ if the model is not new and has not been deleted, +false+
|
143
|
+
# @return [Boolean] +true+ if the model is not new and has not been deleted, +false+
|
155
144
|
# otherwise.
|
156
145
|
def persisted?
|
157
146
|
@data.persisted?
|
@@ -171,7 +160,7 @@ module Aws
|
|
171
160
|
# model.save
|
172
161
|
# model.new_record? # => false
|
173
162
|
#
|
174
|
-
# @return [Boolean] +true+ if the model is newly initialized, +false+
|
163
|
+
# @return [Boolean] +true+ if the model is newly initialized, +false+
|
175
164
|
# otherwise.
|
176
165
|
def new_record?
|
177
166
|
@data.new_record?
|
@@ -190,34 +179,34 @@ module Aws
|
|
190
179
|
# model.destroyed? # => false
|
191
180
|
# model.save
|
192
181
|
# model.destroyed? # => false
|
193
|
-
# model.delete!
|
182
|
+
# model.delete!
|
194
183
|
# model.destroyed? # => true
|
195
184
|
#
|
196
|
-
# @return [Boolean] +true+ if the model has been destroyed, +false+
|
185
|
+
# @return [Boolean] +true+ if the model has been destroyed, +false+
|
197
186
|
# otherwise.
|
198
187
|
def destroyed?
|
199
188
|
@data.destroyed?
|
200
189
|
end
|
201
190
|
|
202
|
-
# Fetches attributes for this instance of an item from Amazon DynamoDB
|
191
|
+
# Fetches attributes for this instance of an item from Amazon DynamoDB
|
203
192
|
# using its primary key and the +find(*)+ class method.
|
204
193
|
#
|
205
|
-
# @raise [Aws::Record::Errors::NotFound] if no record exists in the
|
194
|
+
# @raise [Aws::Record::Errors::NotFound] if no record exists in the
|
206
195
|
# database matching the primary key of the item instance.
|
207
|
-
|
196
|
+
|
208
197
|
# @return [self] Returns the item instance.
|
209
198
|
def reload!
|
210
|
-
primary_key = self.class.keys.values.
|
199
|
+
primary_key = self.class.keys.values.each_with_object({}) do |key, memo|
|
211
200
|
memo[key] = send(key)
|
212
|
-
memo
|
201
|
+
memo
|
213
202
|
end
|
214
203
|
|
215
204
|
record = self.class.find(primary_key)
|
216
205
|
|
217
|
-
|
218
|
-
@data = record.instance_variable_get(
|
206
|
+
if record.present?
|
207
|
+
@data = record.instance_variable_get('@data')
|
219
208
|
else
|
220
|
-
raise Errors::NotFound
|
209
|
+
raise Errors::NotFound, 'No record found'
|
221
210
|
end
|
222
211
|
|
223
212
|
clean!
|
@@ -258,7 +247,7 @@ module Aws
|
|
258
247
|
# model.rollback!
|
259
248
|
# model.name # => 'Alex'
|
260
249
|
#
|
261
|
-
# @param [Array, String, Symbol] names The names of attributes to restore.
|
250
|
+
# @param [Array, String, Symbol] names The names of attributes to restore.
|
262
251
|
def rollback!(names = dirty)
|
263
252
|
Array(names).each { |name| rollback_attribute!(name) }
|
264
253
|
end
|
@@ -276,41 +265,38 @@ module Aws
|
|
276
265
|
end
|
277
266
|
|
278
267
|
module DirtyTrackingClassMethods
|
279
|
-
|
280
268
|
private
|
281
269
|
|
282
270
|
# @private
|
283
271
|
#
|
284
272
|
# @override build_item_from_resp(*)
|
285
273
|
def build_item_from_resp(*)
|
286
|
-
super.tap
|
274
|
+
super.tap(&:clean!)
|
287
275
|
end
|
288
276
|
|
289
277
|
# @private
|
290
278
|
#
|
291
279
|
# @override define_attr_methods(*)
|
292
280
|
def _define_attr_methods(name)
|
293
|
-
super.tap do
|
294
|
-
define_method("#{name}_dirty?") do
|
281
|
+
super.tap do
|
282
|
+
define_method("#{name}_dirty?") do
|
295
283
|
attribute_dirty?(name)
|
296
284
|
end
|
297
285
|
|
298
|
-
define_method("#{name}_dirty!") do
|
286
|
+
define_method("#{name}_dirty!") do
|
299
287
|
attribute_dirty!(name)
|
300
288
|
end
|
301
289
|
|
302
|
-
define_method("#{name}_was") do
|
290
|
+
define_method("#{name}_was") do
|
303
291
|
attribute_was(name)
|
304
292
|
end
|
305
293
|
|
306
|
-
define_method("rollback_#{name}!") do
|
294
|
+
define_method("rollback_#{name}!") do
|
307
295
|
rollback_attribute!(name)
|
308
296
|
end
|
309
297
|
end
|
310
298
|
end
|
311
|
-
|
312
299
|
end
|
313
|
-
|
314
300
|
end
|
315
301
|
end
|
316
302
|
end
|
@@ -1,20 +1,8 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
16
5
|
module Errors
|
17
|
-
|
18
6
|
# RecordErrors relate to the persistence of items. They include both
|
19
7
|
# client errors and certain validation errors.
|
20
8
|
class RecordError < RuntimeError; end
|
@@ -1,15 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
@@ -36,7 +25,7 @@ module Aws
|
|
36
25
|
# @return [Enumerable<Aws::Record>] an enumeration over the results of
|
37
26
|
# your query or scan request. These results are automatically converted
|
38
27
|
# into items on your behalf.
|
39
|
-
def each
|
28
|
+
def each
|
40
29
|
return enum_for(:each) unless block_given?
|
41
30
|
items.each_page do |page|
|
42
31
|
@last_evaluated_key = page.last_evaluated_key
|
@@ -83,19 +72,20 @@ module Aws
|
|
83
72
|
# otherwise.
|
84
73
|
def empty?
|
85
74
|
items.each_page do |page|
|
86
|
-
return false
|
75
|
+
return false unless page.items.empty?
|
87
76
|
end
|
88
77
|
true
|
89
78
|
end
|
90
79
|
|
91
80
|
private
|
81
|
+
|
92
82
|
def _build_items_from_response(items, model)
|
93
83
|
ret = []
|
94
84
|
items.each do |item|
|
95
85
|
model_class = @model_filter ? @model_filter.call(item) : model
|
96
86
|
next unless model_class
|
97
87
|
record = model_class.new
|
98
|
-
data = record.instance_variable_get(
|
88
|
+
data = record.instance_variable_get('@data')
|
99
89
|
model_class.attributes.attributes.each do |name, attr|
|
100
90
|
data.set_attribute(name, attr.extract(item))
|
101
91
|
end
|
@@ -109,7 +99,6 @@ module Aws
|
|
109
99
|
def items
|
110
100
|
@_items ||= @client.send(@search_method, @search_params)
|
111
101
|
end
|
112
|
-
|
113
102
|
end
|
114
103
|
end
|
115
104
|
end
|
@@ -1,19 +1,7 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You may not
|
4
|
-
# use this file except in compliance with the License. A copy of the License is
|
5
|
-
# located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is distributed on
|
10
|
-
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
11
|
-
# or implied. See the License for the specific language governing permissions
|
12
|
-
# and limitations under the License.
|
1
|
+
# frozen_string_literal: true
|
13
2
|
|
14
3
|
module Aws
|
15
4
|
module Record
|
16
|
-
|
17
5
|
# @api private
|
18
6
|
class ItemData
|
19
7
|
def initialize(model_attributes, opts)
|
@@ -28,7 +16,6 @@ module Aws
|
|
28
16
|
|
29
17
|
populate_default_values
|
30
18
|
end
|
31
|
-
|
32
19
|
attr_accessor :new_record, :destroyed
|
33
20
|
|
34
21
|
def get_attribute(name)
|
@@ -86,7 +73,7 @@ module Aws
|
|
86
73
|
end
|
87
74
|
|
88
75
|
def dirty
|
89
|
-
@model_attributes.attributes.keys.
|
76
|
+
@model_attributes.attributes.keys.each_with_object([]) do |name, acc|
|
90
77
|
acc << name if attribute_dirty?(name)
|
91
78
|
acc
|
92
79
|
end
|
@@ -109,7 +96,7 @@ module Aws
|
|
109
96
|
end
|
110
97
|
|
111
98
|
def build_save_hash
|
112
|
-
@data.
|
99
|
+
@data.each_with_object({}) do |name_value_pair, acc|
|
113
100
|
attr_name, raw_value = name_value_pair
|
114
101
|
attribute = @model_attributes.attribute_for(attr_name)
|
115
102
|
if !raw_value.nil? || attribute.persist_nil?
|
@@ -131,11 +118,10 @@ module Aws
|
|
131
118
|
end
|
132
119
|
|
133
120
|
private
|
121
|
+
|
134
122
|
def _deep_copy(obj)
|
135
123
|
Marshal.load(Marshal.dump(obj))
|
136
124
|
end
|
137
|
-
|
138
125
|
end
|
139
|
-
|
140
126
|
end
|
141
127
|
end
|