aws-record 2.10.1 → 2.12.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +83 -19
  3. data/VERSION +1 -1
  4. data/lib/aws-record/record/attribute.rb +8 -8
  5. data/lib/aws-record/record/attributes.rb +36 -49
  6. data/lib/aws-record/record/batch.rb +13 -12
  7. data/lib/aws-record/record/batch_read.rb +10 -12
  8. data/lib/aws-record/record/batch_write.rb +2 -1
  9. data/lib/aws-record/record/buildable_search.rb +37 -39
  10. data/lib/aws-record/record/client_configuration.rb +14 -14
  11. data/lib/aws-record/record/dirty_tracking.rb +29 -40
  12. data/lib/aws-record/record/errors.rb +11 -2
  13. data/lib/aws-record/record/item_collection.rb +7 -7
  14. data/lib/aws-record/record/item_data.rb +13 -17
  15. data/lib/aws-record/record/item_operations.rb +150 -138
  16. data/lib/aws-record/record/key_attributes.rb +0 -2
  17. data/lib/aws-record/record/marshalers/boolean_marshaler.rb +2 -5
  18. data/lib/aws-record/record/marshalers/date_marshaler.rb +1 -6
  19. data/lib/aws-record/record/marshalers/date_time_marshaler.rb +2 -5
  20. data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +2 -8
  21. data/lib/aws-record/record/marshalers/float_marshaler.rb +3 -8
  22. data/lib/aws-record/record/marshalers/integer_marshaler.rb +3 -8
  23. data/lib/aws-record/record/marshalers/list_marshaler.rb +4 -7
  24. data/lib/aws-record/record/marshalers/map_marshaler.rb +4 -7
  25. data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +7 -9
  26. data/lib/aws-record/record/marshalers/string_marshaler.rb +1 -2
  27. data/lib/aws-record/record/marshalers/string_set_marshaler.rb +5 -7
  28. data/lib/aws-record/record/marshalers/time_marshaler.rb +1 -5
  29. data/lib/aws-record/record/model_attributes.rb +17 -29
  30. data/lib/aws-record/record/query.rb +8 -11
  31. data/lib/aws-record/record/secondary_indexes.rb +40 -51
  32. data/lib/aws-record/record/table_config.rb +93 -115
  33. data/lib/aws-record/record/table_migration.rb +56 -72
  34. data/lib/aws-record/record/transactions.rb +40 -43
  35. data/lib/aws-record/record/version.rb +1 -1
  36. data/lib/aws-record/record.rb +36 -44
  37. metadata +13 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b6ed904b6114e07186e11b86c8e8a3e7d94c487cdfc7aba412f2f85a0352528
4
- data.tar.gz: 5a3cbab3c5daf7b820b0d865ab433de7e8a17d9030916dc513e8db8d8c027d0d
3
+ metadata.gz: ffc6a505faafd948f6bd7a553ebd1a6c75ff48d0d77df4b80c2eaae7c550d851
4
+ data.tar.gz: 0721314ff3f6755de1174c494f6d4f9b7b848db2c47106d721ba0458c438aa0f
5
5
  SHA512:
6
- metadata.gz: 9acd345bf2e2280b51e0ed0be2b96a8788f02e358fb9e49ebc91e18f5d6dd1016756e7ce27b36174e15f73084b8e1f5f591d8424d832fd8a27ee5c3794cf1a1c
7
- data.tar.gz: 21995e47b1565913b5ae1812c19074818a5a1ca9ed7b468d6f0f41273458f92d398dc8fdcec64ca4eebef45f49492c1f134939b7ab97274493f0fde157af860e
6
+ metadata.gz: 8b54ae2d2834b31a7fcb32e62e5aab25966ff30fa5fe34b8fe4797507e8a99a37f42eeeb4910e2950f214c07af30f2ec9ea532820ff1ef56569fd17912c803e3
7
+ data.tar.gz: 957101a0f8ad105a613e3b2c33b5f2d3999ebf00bcb83ed0142008ebf213fde862aab433b4eca0403c2b932c35abf7fefc074be2051648e42ecdfda2cf1bbc9f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ 2.12.0 (2023-09-28)
2
+ ------------------
3
+
4
+ * Feature - Allow put, update, and delete item options to be passed through to
5
+ the underlying client calls.
6
+
7
+ * Feature - Add an `original_error` accessor to `Errors::ConditionalWriteFailed`
8
+ which contains the `Aws::DynamoDB::Errors::ConditionalCheckFailedException`
9
+ error. If `:return_values_on_condition_check_failure` was provided to a put,
10
+ update, or delete item call, this error will contain the item data that failed
11
+ the condition check.
12
+
13
+ * Issue - Fix default value for String/Numeric Sets to be unset. (#133)
14
+
15
+ * Feature - Set required Ruby version to >= 2.3 (#134)
16
+
17
+ * Issue - Run Rubocop on all files. (#135)
18
+
19
+ 2.11.0 (2023-06-02)
20
+ ------------------
21
+
22
+ * Feature - Improve User-Agent tracking and bump minimum DynamoDB version.
23
+
1
24
  2.10.1 (2023-01-17)
2
25
  ------------------
3
26
 
@@ -11,7 +34,8 @@
11
34
  2.9.0 (2022-11-16)
12
35
  ------------------
13
36
 
14
- * Feature - Add support for inheritance. Aws Record models can now be extended using standard ruby inheritance (#80).
37
+ * Feature - Add support for inheritance. Aws Record models can now be extended
38
+ using standard ruby inheritance (#80).
15
39
 
16
40
  2.8.0 (2022-10-12)
17
41
  ------------------
@@ -36,7 +60,8 @@
36
60
  2.5.0 (2020-10-13)
37
61
  ------------------
38
62
 
39
- * Feature - `Aws::Record::BuildableSearch` - Support queries yielding heterogeneous results using `multi_model_filter` (#107)
63
+ * Feature - `Aws::Record::BuildableSearch` - Support queries yielding
64
+ heterogeneous results using `multi_model_filter` (#107)
40
65
 
41
66
  2.4.1 (2020-05-29)
42
67
  ------------------
@@ -47,53 +72,89 @@
47
72
  2.4.0 (2019-07-16)
48
73
  ------------------
49
74
 
50
- * Feature - Aws::Record::BuildableSearch - Adds support for query and scan builders using substitution expressions. This allows for streamlined and expressive queries and scans using aws-record.
75
+ * Feature - Aws::Record::BuildableSearch - Adds support for query and scan
76
+ builders using substitution expressions. This allows for streamlined and
77
+ expressive queries and scans using aws-record.
51
78
 
52
79
  2.3.0 (2019-02-08)
53
80
  ------------------
54
81
 
55
- * Feature - Aws::Record::Transactions - Adds support for transactional find and transactional get requests. You can learn more about these new APIs in the [documentation](https://docs.aws.amazon.com/awssdkrubyrecord/api/Aws/Record/Transactions.html).
82
+ * Feature - Aws::Record::Transactions - Adds support for transactional find and
83
+ transactional get requests. You can learn more about these new APIs in
84
+ the [documentation](https://docs.aws.amazon.com/awssdkrubyrecord/api/Aws/Record/Transactions.html).
56
85
 
57
86
  2.2.0 (2018-12-05)
58
87
  ------------------
59
88
 
60
- * Feature - Aws::Record::TableConfig - Adds support for the "PAY_PER_REQUEST" billing mode in table configurations.
89
+ * Feature - Aws::Record::TableConfig - Adds support for the "PAY_PER_REQUEST"
90
+ billing mode in table configurations.
61
91
 
62
92
  2.1.2 (2018-11-15)
63
93
  ------------------
64
94
 
65
- * Issue - Aws::Record::Marshalers::EpochTimeMarshaler - Fixed a bug where epoch time objects didn't properly marshal from database entries.
95
+ * Issue - Aws::Record::Marshalers::EpochTimeMarshaler - Fixed a bug where epoch
96
+ time objects didn't properly marshal from database entries.
66
97
 
67
98
  2.1.1 (2018-07-10)
68
99
  ------------------
69
100
 
70
- * Feature - Aws::Record::TableConfig - Adds `:ttl_attribute` to the TableConfig DSL. When used with `epoch_time_attr` attributes or other attributes stored as epoch time, your TableConfig migrations will enable TTL on your DynamoDB table, and will use your specified attribute as the TTL attribute.
101
+ * Feature - Aws::Record::TableConfig - Adds `:ttl_attribute` to the TableConfig
102
+ DSL. When used with `epoch_time_attr` attributes or other attributes stored as
103
+ epoch time, your TableConfig migrations will enable TTL on your DynamoDB
104
+ table, and will use your specified attribute as the TTL attribute.
71
105
 
72
- * Feature - Aws::Record::Marshalers::EpochTimeMarshaler - Adds the `epoch_time_attr`, which behaves much like `time_attr` except the Amazon DynamoDB storage type is numeric, and the serialized value is epoch seconds.
106
+ * Feature - Aws::Record::Marshalers::EpochTimeMarshaler - Adds
107
+ the `epoch_time_attr`, which behaves much like `time_attr` except the Amazon
108
+ DynamoDB storage type is numeric, and the serialized value is epoch seconds.
73
109
 
74
110
  2.1.0 (2018-06-25)
75
111
  ------------------
76
112
 
77
- * Feature - Aws::Record - Add the `persisted?`, `new_record?`, and `destroyed?` methods to `Aws::Record`, which supports use cases where you'd like to see if a record has just been newly initialized, or has been deleted or was a preexisting record retrieved from DynamoDB. Note that these methods are present in `ActiveModel::Model` so you should require that module before `Aws::Record`
113
+ * Feature - Aws::Record - Add the `persisted?`, `new_record?`, and `destroyed?`
114
+ methods to `Aws::Record`, which supports use cases where you'd like to see if
115
+ a record has just been newly initialized, or has been deleted or was a
116
+ preexisting record retrieved from DynamoDB. Note that these methods are
117
+ present in `ActiveModel::Model` so you should require that module
118
+ before `Aws::Record`
78
119
 
79
- * Feature - Aws::Record - Add the `assign_attributes`, `update`, and `update!` methods to `Aws::Record` which supports the use case where the user might want to mass assign or update a records attributes by hash. `update!` also ensures that a `ValidationError` is thrown on an invalid update
120
+ * Feature - Aws::Record - Add the `assign_attributes`, `update`, and `update!`
121
+ methods to `Aws::Record` which supports the use case where the user might want
122
+ to mass assign or update a records attributes by hash. `update!` also ensures
123
+ that a `ValidationError` is thrown on an invalid update
80
124
 
81
- * Upgrading - If you already include `ActiveModel::Model` on your models the new `persisted?`, `new_record?` and `destroyed?` methods will not function properly unless you include `ActiveModel::Model` before `Aws::Record`. Additionally, new methods could lead to collisions if you happened to have attributes such as `:update` or `:assign_attributes`. In such a case, you would want to version lock below `2.1.0`, or use the `:database_attribute_name` property and change your attribute name in code.
125
+ * Upgrading - If you already include `ActiveModel::Model` on your models the
126
+ new `persisted?`, `new_record?` and `destroyed?` methods will not function
127
+ properly unless you include `ActiveModel::Model` before `Aws::Record`.
128
+ Additionally, new methods could lead to collisions if you happened to have
129
+ attributes such as `:update` or `:assign_attributes`. In such a case, you
130
+ would want to version lock below `2.1.0`, or use
131
+ the `:database_attribute_name` property and change your attribute name in
132
+ code.
82
133
 
83
134
  2.0.2 (2018-06-08)
84
135
  ------------------
85
136
 
86
- * Feature - Aws::Record::Marshalers::TimeMarshaler - Adds the `time_attr` method to AWS Record models, which uses `Time` as the underlying type.
137
+ * Feature - Aws::Record::Marshalers::TimeMarshaler - Adds the `time_attr` method
138
+ to AWS Record models, which uses `Time` as the underlying type.
87
139
 
88
140
  2.0.1 (2017-10-27)
89
141
  ------------------
90
142
 
91
- * Feature - Aws::Record::ItemCollection - Add the `#page` and `#last_evaluated_key` methods to `Aws::Record::ItemCollection`. This helps to support use cases where you'd like to control the result set size with the `:limit` parameter, or if you want to expose pagination capabilities to an outside caller, for example a list-type operation exposed in a web API.
143
+ * Feature - Aws::Record::ItemCollection - Add the `#page`
144
+ and `#last_evaluated_key` methods to `Aws::Record::ItemCollection`. This helps
145
+ to support use cases where you'd like to control the result set size with
146
+ the `:limit` parameter, or if you want to expose pagination capabilities to an
147
+ outside caller, for example a list-type operation exposed in a web API.
92
148
 
93
149
  2.0.0 (2017-08-29)
94
150
  ------------------
95
151
 
96
- * Upgrading - Aws::Record - Support version 3 of the AWS SDK for Ruby. This is being released as major version 2 of `aws-record`, though the APIs remain the same. Do note, however, that we've changed our SDK dependency to only depend on `aws-sdk-dynamodb`. This means that if you were depending on other service clients transitively via `aws-record`, you will need to add dependencies on the appropriate service gems when upgrading.
152
+ * Upgrading - Aws::Record - Support version 3 of the AWS SDK for Ruby. This is
153
+ being released as major version 2 of `aws-record`, though the APIs remain the
154
+ same. Do note, however, that we've changed our SDK dependency to only depend
155
+ on `aws-sdk-dynamodb`. This means that if you were depending on other service
156
+ clients transitively via `aws-record`, you will need to add dependencies on
157
+ the appropriate service gems when upgrading.
97
158
 
98
159
  1.1.1 (2017-06-16)
99
160
  ------------------
@@ -155,18 +216,21 @@
155
216
  1.0.0.pre.10 (2016-08-03)
156
217
  ------------------
157
218
 
158
- * Feature - Aws::Record - Refactored tracking of model attributes, key attributes,
159
- and item data to use internal classes over module composition. Dirty tracking is
219
+ * Feature - Aws::Record - Refactored tracking of model attributes, key
220
+ attributes,
221
+ and item data to use internal classes over module composition. Dirty tracking
222
+ is
160
223
  also handled more consistently across attributes, and turning on/off of dirty
161
224
  tracking is only possible at the model level (not for individual attributes).
162
225
 
163
226
  1.0.0.pre.9 (2016-07-22)
164
227
  ------------------
165
228
 
166
- * Feature - Aws::Record::Attribute - Added support for default values at the attribute
167
- level.
229
+ * Feature - Aws::Record::Attribute - Added support for default values at the
230
+ attribute level.
168
231
 
169
- * Feature - Aws::Record::Marshalers - Removed the marshalers in the `Aws::Attributes`
232
+ * Feature - Aws::Record::Marshalers - Removed the marshalers in
233
+ the `Aws::Attributes`
170
234
  namespace, replacing them with instantiated marshaler objects. This enables
171
235
  more functionality in marshalers such as the Date/DateTime marshalers.
172
236
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.10.1
1
+ 2.12.0
@@ -2,14 +2,12 @@
2
2
 
3
3
  module Aws
4
4
  module Record
5
-
6
5
  # This class provides helper methods for +Aws::Record+ attributes. These
7
6
  # include marshalers for type casting of item attributes, the Amazon
8
7
  # DynamoDB type for use in certain table and item operation calls, and the
9
8
  # ability to define a database name that is separate from the name used
10
9
  # within the model class and item instances.
11
10
  class Attribute
12
-
13
11
  attr_reader :name, :database_name, :dynamodb_type
14
12
 
15
13
  # @param [Symbol] name Name of the attribute. It should be a name that is
@@ -38,12 +36,14 @@ module Aws
38
36
  # be used as a default value.
39
37
  def initialize(name, options = {})
40
38
  @name = name
41
- @database_name = (options[:database_attribute_name] || name).to_s
39
+ @database_name = (options[:database_attribute_name] || name).to_s
42
40
  @dynamodb_type = options[:dynamodb_type]
43
41
  @marshaler = options[:marshaler] || DefaultMarshaler
44
42
  @persist_nil = options[:persist_nil]
45
- dv = options[:default_value]
46
- @default_value_or_lambda = _is_lambda?(dv) ? dv : type_cast(dv)
43
+ @default_value_or_lambda = if options.key?(:default_value)
44
+ dv = options[:default_value]
45
+ _is_lambda?(dv) ? dv : type_cast(dv)
46
+ end
47
47
  end
48
48
 
49
49
  # Attempts to type cast a raw value into the attribute's type. This call
@@ -90,6 +90,7 @@ module Aws
90
90
  end
91
91
 
92
92
  private
93
+
93
94
  def _deep_copy(obj)
94
95
  Marshal.load(Marshal.dump(obj))
95
96
  end
@@ -97,17 +98,16 @@ module Aws
97
98
  def _is_lambda?(obj)
98
99
  obj.respond_to?(:call)
99
100
  end
100
-
101
101
  end
102
102
 
103
103
  # This is an identity marshaler, which performs no changes for type casting
104
104
  # or serialization. It is generally not recommended for use.
105
105
  module DefaultMarshaler
106
- def self.type_cast(raw_value, options = {})
106
+ def self.type_cast(raw_value, _options = {})
107
107
  raw_value
108
108
  end
109
109
 
110
- def self.serialize(raw_value, options = {})
110
+ def self.serialize(raw_value, _options = {})
111
111
  raw_value
112
112
  end
113
113
  end
@@ -3,15 +3,12 @@
3
3
  module Aws
4
4
  module Record
5
5
  module Attributes
6
-
7
6
  def self.included(sub_class)
8
7
  sub_class.extend(ClassMethods)
9
8
  model_attributes = ModelAttributes.new(self)
10
- sub_class.instance_variable_set("@attributes", model_attributes)
11
- sub_class.instance_variable_set("@keys", KeyAttributes.new(model_attributes))
12
- if Aws::Record.extends_record?(sub_class)
13
- inherit_attributes(sub_class)
14
- end
9
+ sub_class.instance_variable_set('@attributes', model_attributes)
10
+ sub_class.instance_variable_set('@keys', KeyAttributes.new(model_attributes))
11
+ inherit_attributes(sub_class) if Aws::Record.extends_record?(sub_class)
15
12
  end
16
13
 
17
14
  # Base initialization method for a new item. Optionally, allows you to
@@ -80,29 +77,24 @@ module Aws
80
77
  @data.hash_copy
81
78
  end
82
79
 
83
- private
84
80
  def self.inherit_attributes(klass)
85
- superclass_attributes = klass.superclass.instance_variable_get("@attributes")
81
+ superclass_attributes = klass.superclass.instance_variable_get('@attributes')
86
82
 
87
83
  superclass_attributes.attributes.each do |name, attribute|
88
- subclass_attributes = klass.instance_variable_get("@attributes")
84
+ subclass_attributes = klass.instance_variable_get('@attributes')
89
85
  subclass_attributes.register_superclass_attribute(name, attribute)
90
86
  end
91
87
 
92
- superclass_keys = klass.superclass.instance_variable_get("@keys")
93
- subclass_keys = klass.instance_variable_get("@keys")
94
-
95
- if superclass_keys.hash_key
96
- subclass_keys.hash_key = superclass_keys.hash_key
97
- end
88
+ superclass_keys = klass.superclass.instance_variable_get('@keys')
89
+ subclass_keys = klass.instance_variable_get('@keys')
98
90
 
99
- if superclass_keys.range_key
100
- subclass_keys.range_key = superclass_keys.range_key
101
- end
91
+ subclass_keys.hash_key = superclass_keys.hash_key if superclass_keys.hash_key
92
+ subclass_keys.range_key = superclass_keys.range_key if superclass_keys.range_key
102
93
  end
103
94
 
104
- module ClassMethods
95
+ private_class_method :inherit_attributes
105
96
 
97
+ module ClassMethods
106
98
  # Define an attribute for your model, providing your own attribute type.
107
99
  #
108
100
  # @param [Symbol] name Name of this attribute. It should be a name that
@@ -157,7 +149,7 @@ module Aws
157
149
  # item is nil or not set at persistence time. Additionally, lambda
158
150
  # can be used as a default value.
159
151
  def string_attr(name, opts = {})
160
- opts[:dynamodb_type] = "S"
152
+ opts[:dynamodb_type] = 'S'
161
153
  attr(name, Marshalers::StringMarshaler.new(opts), opts)
162
154
  end
163
155
 
@@ -179,7 +171,7 @@ module Aws
179
171
  # item is nil or not set at persistence time. Additionally, lambda
180
172
  # can be used as a default value.
181
173
  def boolean_attr(name, opts = {})
182
- opts[:dynamodb_type] = "BOOL"
174
+ opts[:dynamodb_type] = 'BOOL'
183
175
  attr(name, Marshalers::BooleanMarshaler.new(opts), opts)
184
176
  end
185
177
 
@@ -201,7 +193,7 @@ module Aws
201
193
  # item is nil or not set at persistence time. Additionally, lambda
202
194
  # can be used as a default value.
203
195
  def integer_attr(name, opts = {})
204
- opts[:dynamodb_type] = "N"
196
+ opts[:dynamodb_type] = 'N'
205
197
  attr(name, Marshalers::IntegerMarshaler.new(opts), opts)
206
198
  end
207
199
 
@@ -223,7 +215,7 @@ module Aws
223
215
  # item is nil or not set at persistence time. Additionally, lambda
224
216
  # can be used as a default value.
225
217
  def float_attr(name, opts = {})
226
- opts[:dynamodb_type] = "N"
218
+ opts[:dynamodb_type] = 'N'
227
219
  attr(name, Marshalers::FloatMarshaler.new(opts), opts)
228
220
  end
229
221
 
@@ -245,7 +237,7 @@ module Aws
245
237
  # item is nil or not set at persistence time. Additionally, lambda
246
238
  # can be used as a default value.
247
239
  def date_attr(name, opts = {})
248
- opts[:dynamodb_type] = "S"
240
+ opts[:dynamodb_type] = 'S'
249
241
  attr(name, Marshalers::DateMarshaler.new(opts), opts)
250
242
  end
251
243
 
@@ -267,7 +259,7 @@ module Aws
267
259
  # item is nil or not set at persistence time. Additionally, lambda
268
260
  # can be used as a default value.
269
261
  def datetime_attr(name, opts = {})
270
- opts[:dynamodb_type] = "S"
262
+ opts[:dynamodb_type] = 'S'
271
263
  attr(name, Marshalers::DateTimeMarshaler.new(opts), opts)
272
264
  end
273
265
 
@@ -289,7 +281,7 @@ module Aws
289
281
  # item is nil or not set at persistence time. Additionally, lambda
290
282
  # can be used as a default value.
291
283
  def time_attr(name, opts = {})
292
- opts[:dynamodb_type] = "S"
284
+ opts[:dynamodb_type] = 'S'
293
285
  attr(name, Marshalers::TimeMarshaler.new(opts), opts)
294
286
  end
295
287
 
@@ -312,7 +304,7 @@ module Aws
312
304
  # item is nil or not set at persistence time. Additionally, lambda
313
305
  # can be used as a default value.
314
306
  def epoch_time_attr(name, opts = {})
315
- opts[:dynamodb_type] = "N"
307
+ opts[:dynamodb_type] = 'N'
316
308
  attr(name, Marshalers::EpochTimeMarshaler.new(opts), opts)
317
309
  end
318
310
 
@@ -348,7 +340,7 @@ module Aws
348
340
  # item is nil or not set at persistence time. Additionally, lambda
349
341
  # can be used as a default value.
350
342
  def list_attr(name, opts = {})
351
- opts[:dynamodb_type] = "L"
343
+ opts[:dynamodb_type] = 'L'
352
344
  attr(name, Marshalers::ListMarshaler.new(opts), opts)
353
345
  end
354
346
 
@@ -384,7 +376,7 @@ module Aws
384
376
  # item is nil or not set at persistence time. Additionally, lambda
385
377
  # can be used as a default value.
386
378
  def map_attr(name, opts = {})
387
- opts[:dynamodb_type] = "M"
379
+ opts[:dynamodb_type] = 'M'
388
380
  attr(name, Marshalers::MapMarshaler.new(opts), opts)
389
381
  end
390
382
 
@@ -410,7 +402,7 @@ module Aws
410
402
  # item is nil or not set at persistence time. Additionally, lambda
411
403
  # can be used as a default value.
412
404
  def string_set_attr(name, opts = {})
413
- opts[:dynamodb_type] = "SS"
405
+ opts[:dynamodb_type] = 'SS'
414
406
  attr(name, Marshalers::StringSetMarshaler.new(opts), opts)
415
407
  end
416
408
 
@@ -436,7 +428,7 @@ module Aws
436
428
  # item is nil or not set at persistence time. Additionally, lambda
437
429
  # can be used as a default value.
438
430
  def numeric_set_attr(name, opts = {})
439
- opts[:dynamodb_type] = "NS"
431
+ opts[:dynamodb_type] = 'NS'
440
432
  attr(name, Marshalers::NumericSetMarshaler.new(opts), opts)
441
433
  end
442
434
 
@@ -452,8 +444,8 @@ module Aws
452
444
  # * None of the attributes have dirty changes.
453
445
  # * If there is a value passed in, it must be an integer.
454
446
  # For more information, see
455
- # {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters Atomic counter}
456
- # in the Amazon DynamoDB Developer Guide.
447
+ # {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters
448
+ # Atomic counter} in the Amazon DynamoDB Developer Guide.
457
449
  #
458
450
  # @param [Symbol] name Name of this attribute. It should be a name that
459
451
  # is safe to use as a method.
@@ -476,14 +468,13 @@ module Aws
476
468
  # record.increment_counter!(2) #=> 3
477
469
  # @see #attr #attr method for additional hash options.
478
470
  def atomic_counter(name, opts = {})
479
- opts[:dynamodb_type] = "N"
471
+ opts[:dynamodb_type] = 'N'
480
472
  opts[:default_value] ||= 0
481
473
  attr(name, Marshalers::IntegerMarshaler.new(opts), opts)
482
474
 
483
- define_method("increment_#{name}!") do |increment=1|
484
-
475
+ define_method("increment_#{name}!") do |increment = 1|
485
476
  if dirty?
486
- msg = "Attributes need to be saved before atomic counter can be incremented"
477
+ msg = 'Attributes need to be saved before atomic counter can be incremented'
487
478
  raise Errors::RecordError, msg
488
479
  end
489
480
 
@@ -492,23 +483,22 @@ module Aws
492
483
  raise ArgumentError, msg
493
484
  end
494
485
 
495
- resp = dynamodb_client.update_item({
486
+ resp = dynamodb_client.update_item(
496
487
  table_name: self.class.table_name,
497
488
  key: key_values,
498
489
  expression_attribute_values: {
499
- ":i" => increment
490
+ ':i' => increment
500
491
  },
501
492
  expression_attribute_names: {
502
- "#n" => name
493
+ '#n' => name
503
494
  },
504
- update_expression: "SET #n = #n + :i",
505
- return_values: "UPDATED_NEW"
506
- })
495
+ update_expression: 'SET #n = #n + :i',
496
+ return_values: 'UPDATED_NEW'
497
+ )
507
498
  assign_attributes(resp[:attributes])
508
499
  @data.clean!
509
500
  @data.get_attribute(name)
510
501
  end
511
-
512
502
  end
513
503
 
514
504
  # @return [Symbol,nil] The symbolic name of the table's hash key.
@@ -532,6 +522,7 @@ module Aws
532
522
  end
533
523
 
534
524
  private
525
+
535
526
  def _define_attr_methods(name)
536
527
  define_method(name) do
537
528
  @data.get_attribute(name)
@@ -544,18 +535,14 @@ module Aws
544
535
 
545
536
  def _key_attributes(id, opts)
546
537
  if opts[:hash_key] == true && opts[:range_key] == true
547
- raise ArgumentError.new(
548
- "Cannot have the same attribute be a hash and range key."
549
- )
538
+ raise ArgumentError, 'Cannot have the same attribute be a hash and range key.'
550
539
  elsif opts[:hash_key] == true
551
540
  @keys.hash_key = id
552
541
  elsif opts[:range_key] == true
553
542
  @keys.range_key = id
554
543
  end
555
544
  end
556
-
557
545
  end
558
-
559
546
  end
560
547
  end
561
548
  end
@@ -7,10 +7,10 @@ module Aws
7
7
 
8
8
  class << self
9
9
  # Provides a thin wrapper to the
10
- # {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method Aws::DynamoDB::Client#batch_write_item}
11
- # method. Up to 25 +PutItem+ or +DeleteItem+ operations are supported.
12
- # A single request may write up to 16 MB of data, with each item having a
13
- # write limit of 400 KB.
10
+ # {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#batch_write_item-instance_method
11
+ # Aws::DynamoDB::Client#batch_write_item} method. Up to 25 +PutItem+ or +DeleteItem+
12
+ # operations are supported. A single request may write up to 16 MB of data, with each
13
+ # item having a write limit of 400 KB.
14
14
  #
15
15
  # *Note*: this operation does not support dirty attribute handling,
16
16
  # nor does it enforce safe write operations (i.e. update vs new record
@@ -25,8 +25,9 @@ module Aws
25
25
  # when all operations have been completed.
26
26
  #
27
27
  # Please see
28
- # {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html#Programming.Errors.BatchOperations Batch Operations and Error Handling}
29
- # in the DynamoDB Developer Guide for more details.
28
+ # {https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Programming.Errors.html#Programming.Errors.BatchOperations
29
+ # Batch Operations and Error Handling} in the DynamoDB Developer Guide for
30
+ # more details.
30
31
  #
31
32
  # @example Usage Example
32
33
  # class Breakfast
@@ -54,15 +55,16 @@ module Aws
54
55
  # @param [Hash] opts the options you wish to use to create the client.
55
56
  # Note that if you include the option +:client+, all other options
56
57
  # will be ignored. See the documentation for other options in the
57
- # {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method AWS SDK for Ruby}.
58
+ # {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#initialize-instance_method
59
+ # AWS SDK for Ruby}.
58
60
  # @option opts [Aws::DynamoDB::Client] :client allows you to pass in your
59
61
  # own pre-configured client.
60
62
  #
61
63
  # @return [Aws::Record::BatchWrite] An instance that contains any
62
64
  # unprocessed items and allows for a retry strategy.
63
- def write(opts = {}, &block)
65
+ def write(opts = {})
64
66
  batch = BatchWrite.new(client: _build_client(opts))
65
- block.call(batch)
67
+ yield(batch)
66
68
  batch.execute!
67
69
  end
68
70
 
@@ -133,13 +135,12 @@ module Aws
133
135
  # @return [Aws::Record::BatchRead] An instance that contains modeled items
134
136
  # from the +BatchGetItem+ result and stores unprocessed keys to be
135
137
  # manually processed later.
136
- def read(opts = {}, &block)
138
+ def read(opts = {})
137
139
  batch = BatchRead.new(client: _build_client(opts))
138
- block.call(batch)
140
+ yield(batch)
139
141
  batch.execute!
140
142
  batch
141
143
  end
142
-
143
144
  end
144
145
  end
145
146
  end
@@ -8,7 +8,8 @@ module Aws
8
8
  # @api private
9
9
  BATCH_GET_ITEM_LIMIT = 100
10
10
 
11
- # @param [Aws::DynamoDB::Client] client the DynamoDB SDK client.
11
+ # @param [Hash] opts
12
+ # @option opts [Aws::DynamoDB::Client] client the DynamoDB SDK client.
12
13
  def initialize(opts = {})
13
14
  @client = opts[:client]
14
15
  end
@@ -44,9 +45,7 @@ module Aws
44
45
  new_items = build_items(result.responses)
45
46
  items.concat(new_items)
46
47
 
47
- unless result.unprocessed_keys.nil?
48
- update_unprocessed_keys(result.unprocessed_keys)
49
- end
48
+ update_unprocessed_keys(result.unprocessed_keys) unless result.unprocessed_keys.nil?
50
49
 
51
50
  new_items
52
51
  end
@@ -61,13 +60,14 @@ module Aws
61
60
  # @yieldparam [Aws::Record] item a modeled item
62
61
  # @return [Enumerable<BatchRead>] an enumeration over the results of
63
62
  # +batch_get_item+ request.
64
- def each
63
+ def each(&block)
65
64
  return enum_for(:each) unless block_given?
66
65
 
67
- @items.each { |item| yield item }
66
+ @items.each(&block)
67
+
68
68
  until complete?
69
69
  new_items = execute!
70
- new_items.each { |new_item| yield new_item }
70
+ new_items.each(&block)
71
71
  end
72
72
  end
73
73
 
@@ -102,9 +102,7 @@ module Aws
102
102
  item_key = {}
103
103
  attributes = klass.attributes
104
104
  klass.keys.each_value do |attr_sym|
105
- unless key[attr_sym]
106
- raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{key}"
107
- end
105
+ raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{key}" unless key[attr_sym]
108
106
 
109
107
  attr_name = attributes.storage_name_for(attr_sym)
110
108
  item_key[attr_name] = attributes.attribute_for(attr_sym)
@@ -143,7 +141,7 @@ module Aws
143
141
  item_class = find_item_class(table, item)
144
142
  if item_class.nil? && @client.config.logger
145
143
  @client.config.logger.warn(
146
- 'Unexpected response from service.'\
144
+ 'Unexpected response from service.' \
147
145
  "Received: #{item}. Skipping above item and continuing"
148
146
  )
149
147
  else
@@ -156,7 +154,7 @@ module Aws
156
154
 
157
155
  def update_unprocessed_keys(keys)
158
156
  keys.each do |table_name, table_values|
159
- table_values.keys.each do |key|
157
+ table_values.keys.each do |key| # rubocop:disable Style/HashEachMethods
160
158
  unprocessed_keys << { keys: key, table_name: table_name }
161
159
  end
162
160
  end
@@ -3,7 +3,8 @@
3
3
  module Aws
4
4
  module Record
5
5
  class BatchWrite
6
- # @param [Aws::DynamoDB::Client] client the DynamoDB SDK client.
6
+ # @param [Hash] opts
7
+ # @option opts [Aws::DynamoDB::Client] client the DynamoDB SDK client.
7
8
  def initialize(opts = {})
8
9
  @client = opts[:client]
9
10
  end