aws-record 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -19
  3. data/VERSION +1 -1
  4. data/lib/aws-record/record/attribute.rb +4 -2
  5. data/lib/aws-record/record/batch_read.rb +8 -13
  6. data/lib/aws-record/record/batch_write.rb +2 -1
  7. data/lib/aws-record/record/buildable_search.rb +15 -20
  8. data/lib/aws-record/record/client_configuration.rb +7 -7
  9. data/lib/aws-record/record/dirty_tracking.rb +3 -11
  10. data/lib/aws-record/record/errors.rb +11 -1
  11. data/lib/aws-record/record/item_collection.rb +5 -5
  12. data/lib/aws-record/record/item_data.rb +10 -11
  13. data/lib/aws-record/record/item_operations.rb +98 -70
  14. data/lib/aws-record/record/marshalers/boolean_marshaler.rb +4 -4
  15. data/lib/aws-record/record/marshalers/date_marshaler.rb +1 -3
  16. data/lib/aws-record/record/marshalers/date_time_marshaler.rb +1 -3
  17. data/lib/aws-record/record/marshalers/epoch_time_marshaler.rb +2 -6
  18. data/lib/aws-record/record/marshalers/float_marshaler.rb +4 -4
  19. data/lib/aws-record/record/marshalers/integer_marshaler.rb +4 -4
  20. data/lib/aws-record/record/marshalers/list_marshaler.rb +6 -6
  21. data/lib/aws-record/record/marshalers/map_marshaler.rb +6 -6
  22. data/lib/aws-record/record/marshalers/numeric_set_marshaler.rb +7 -7
  23. data/lib/aws-record/record/marshalers/string_marshaler.rb +3 -1
  24. data/lib/aws-record/record/marshalers/string_set_marshaler.rb +6 -6
  25. data/lib/aws-record/record/marshalers/time_marshaler.rb +1 -3
  26. data/lib/aws-record/record/model_attributes.rb +14 -16
  27. data/lib/aws-record/record/query.rb +4 -4
  28. data/lib/aws-record/record/secondary_indexes.rb +22 -25
  29. data/lib/aws-record/record/table_config.rb +45 -56
  30. data/lib/aws-record/record/table_migration.rb +32 -36
  31. data/lib/aws-record/record/transactions.rb +18 -18
  32. data/lib/aws-record/record/version.rb +1 -1
  33. data/lib/aws-record/record.rb +8 -8
  34. metadata +4 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 737cba9ded94a3d3785cda00b45989e7deee3592c53cae2f4a63a769f1ba3f55
4
- data.tar.gz: 1f086b7c3958985bc57ca2a39b22255e88cee84fe0930118ad6c5b8ff78e3c2c
3
+ metadata.gz: ffc6a505faafd948f6bd7a553ebd1a6c75ff48d0d77df4b80c2eaae7c550d851
4
+ data.tar.gz: 0721314ff3f6755de1174c494f6d4f9b7b848db2c47106d721ba0458c438aa0f
5
5
  SHA512:
6
- metadata.gz: 5cd823dc1edfe588f87d2b7f770a4fa25ca248a055940196264660b803bac3ecce4714f6fb5cb157e1d7d0a668b41bcade92de49851f87f336aaacc6406af167
7
- data.tar.gz: 3174f0eb63e34a421b3cbe4c494f7c86ddf5a66e1da6e572351a294cbdfad89b4bd0a41197b7b569b67967e270fe57a9e8f5b07ddedb411d1225e27a0c958b9b
6
+ metadata.gz: 8b54ae2d2834b31a7fcb32e62e5aab25966ff30fa5fe34b8fe4797507e8a99a37f42eeeb4910e2950f214c07af30f2ec9ea532820ff1ef56569fd17912c803e3
7
+ data.tar.gz: 957101a0f8ad105a613e3b2c33b5f2d3999ebf00bcb83ed0142008ebf213fde862aab433b4eca0403c2b932c35abf7fefc074be2051648e42ecdfda2cf1bbc9f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
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
+
1
19
  2.11.0 (2023-06-02)
2
20
  ------------------
3
21
 
@@ -16,7 +34,8 @@
16
34
  2.9.0 (2022-11-16)
17
35
  ------------------
18
36
 
19
- * 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).
20
39
 
21
40
  2.8.0 (2022-10-12)
22
41
  ------------------
@@ -41,7 +60,8 @@
41
60
  2.5.0 (2020-10-13)
42
61
  ------------------
43
62
 
44
- * 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)
45
65
 
46
66
  2.4.1 (2020-05-29)
47
67
  ------------------
@@ -52,53 +72,89 @@
52
72
  2.4.0 (2019-07-16)
53
73
  ------------------
54
74
 
55
- * 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.
56
78
 
57
79
  2.3.0 (2019-02-08)
58
80
  ------------------
59
81
 
60
- * 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).
61
85
 
62
86
  2.2.0 (2018-12-05)
63
87
  ------------------
64
88
 
65
- * 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.
66
91
 
67
92
  2.1.2 (2018-11-15)
68
93
  ------------------
69
94
 
70
- * 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.
71
97
 
72
98
  2.1.1 (2018-07-10)
73
99
  ------------------
74
100
 
75
- * 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.
76
105
 
77
- * 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.
78
109
 
79
110
  2.1.0 (2018-06-25)
80
111
  ------------------
81
112
 
82
- * 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`
83
119
 
84
- * 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
85
124
 
86
- * 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.
87
133
 
88
134
  2.0.2 (2018-06-08)
89
135
  ------------------
90
136
 
91
- * 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.
92
139
 
93
140
  2.0.1 (2017-10-27)
94
141
  ------------------
95
142
 
96
- * 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.
97
148
 
98
149
  2.0.0 (2017-08-29)
99
150
  ------------------
100
151
 
101
- * 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.
102
158
 
103
159
  1.1.1 (2017-06-16)
104
160
  ------------------
@@ -160,18 +216,21 @@
160
216
  1.0.0.pre.10 (2016-08-03)
161
217
  ------------------
162
218
 
163
- * Feature - Aws::Record - Refactored tracking of model attributes, key attributes,
164
- 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
165
223
  also handled more consistently across attributes, and turning on/off of dirty
166
224
  tracking is only possible at the model level (not for individual attributes).
167
225
 
168
226
  1.0.0.pre.9 (2016-07-22)
169
227
  ------------------
170
228
 
171
- * Feature - Aws::Record::Attribute - Added support for default values at the attribute
172
- level.
229
+ * Feature - Aws::Record::Attribute - Added support for default values at the
230
+ attribute level.
173
231
 
174
- * Feature - Aws::Record::Marshalers - Removed the marshalers in the `Aws::Attributes`
232
+ * Feature - Aws::Record::Marshalers - Removed the marshalers in
233
+ the `Aws::Attributes`
175
234
  namespace, replacing them with instantiated marshaler objects. This enables
176
235
  more functionality in marshalers such as the Date/DateTime marshalers.
177
236
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.11.0
1
+ 2.12.0
@@ -40,8 +40,10 @@ module Aws
40
40
  @dynamodb_type = options[:dynamodb_type]
41
41
  @marshaler = options[:marshaler] || DefaultMarshaler
42
42
  @persist_nil = options[:persist_nil]
43
- dv = options[:default_value]
44
- @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
45
47
  end
46
48
 
47
49
  # Attempts to type cast a raw value into the attribute's type. This call
@@ -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,16 +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 do |item|
68
- yield(item)
69
- end
66
+ @items.each(&block)
70
67
 
71
68
  until complete?
72
69
  new_items = execute!
73
- new_items.each { |new_item| yield new_item }
70
+ new_items.each(&block)
74
71
  end
75
72
  end
76
73
 
@@ -105,9 +102,7 @@ module Aws
105
102
  item_key = {}
106
103
  attributes = klass.attributes
107
104
  klass.keys.each_value do |attr_sym|
108
- unless key[attr_sym]
109
- raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{key}"
110
- end
105
+ raise Errors::KeyMissing, "Missing required key #{attr_sym} in #{key}" unless key[attr_sym]
111
106
 
112
107
  attr_name = attributes.storage_name_for(attr_sym)
113
108
  item_key[attr_name] = attributes.attribute_for(attr_sym)
@@ -146,7 +141,7 @@ module Aws
146
141
  item_class = find_item_class(table, item)
147
142
  if item_class.nil? && @client.config.logger
148
143
  @client.config.logger.warn(
149
- 'Unexpected response from service.'\
144
+ 'Unexpected response from service.' \
150
145
  "Received: #{item}. Skipping above item and continuing"
151
146
  )
152
147
  else
@@ -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
@@ -10,11 +10,10 @@ module Aws
10
10
  def initialize(opts)
11
11
  operation = opts[:operation]
12
12
  model = opts[:model]
13
- if SUPPORTED_OPERATIONS.include?(operation)
14
- @operation = operation
15
- else
16
- raise ArgumentError, "Unsupported operation: #{operation}"
17
- end
13
+ raise ArgumentError, "Unsupported operation: #{operation}" unless SUPPORTED_OPERATIONS.include?(operation)
14
+
15
+ @operation = operation
16
+
18
17
  @model = model
19
18
  @params = {}
20
19
  @next_name = 'BUILDERA'
@@ -41,12 +40,11 @@ module Aws
41
40
  # builder method to provide the :total_segments of your parallel scan and
42
41
  # the :segment number of this scan.
43
42
  def parallel_scan(opts)
44
- unless @operation == :scan
45
- raise ArgumentError, 'parallel_scan is only supported for scans'
46
- end
43
+ raise ArgumentError, 'parallel_scan is only supported for scans' unless @operation == :scan
47
44
  unless opts[:total_segments] && opts[:segment]
48
45
  raise ArgumentError, 'Must specify :total_segments and :segment in a parallel scan.'
49
46
  end
47
+
50
48
  @params[:total_segments] = opts[:total_segments]
51
49
  @params[:segment] = opts[:segment]
52
50
  self
@@ -56,9 +54,8 @@ module Aws
56
54
  # ascending or descending order on your range key. By default, a query is
57
55
  # run in ascending order.
58
56
  def scan_ascending(b)
59
- unless @operation == :query
60
- raise ArgumentError, 'scan_ascending is only supported for queries.'
61
- end
57
+ raise ArgumentError, 'scan_ascending is only supported for queries.' unless @operation == :query
58
+
62
59
  @params[:scan_index_forward] = b
63
60
  self
64
61
  end
@@ -90,9 +87,8 @@ module Aws
90
87
  # ).complete!
91
88
  # q.to_a # You can use this like any other query result in aws-record
92
89
  def key_expr(statement_str, *subs)
93
- unless @operation == :query
94
- raise ArgumentError, 'key_expr is only supported for queries.'
95
- end
90
+ raise ArgumentError, 'key_expr is only supported for queries.' unless @operation == :query
91
+
96
92
  names = @params[:expression_attribute_names]
97
93
  if names.nil?
98
94
  @params[:expression_attribute_names] = {}
@@ -252,28 +248,27 @@ module Aws
252
248
 
253
249
  def _apply_values(statement, subs, values)
254
250
  count = 0
255
- result = statement.gsub(/[?]/) do ||
251
+ result = statement.gsub(/[?]/) do
256
252
  sub_value = _next_value
257
253
  raise 'Substitution collision!' if values[sub_value]
254
+
258
255
  values[sub_value] = subs[count]
259
256
  count += 1
260
257
  sub_value
261
258
  end
262
259
  result.tap do
263
- unless count == subs.size
264
- raise "Expected #{count} values in the substitution set, but found #{subs.size}"
265
- end
260
+ raise "Expected #{count} values in the substitution set, but found #{subs.size}" unless count == subs.size
266
261
  end
267
262
  end
268
263
 
269
264
  def _next_name
270
- ret = '#' + @next_name
265
+ ret = "##{@next_name}"
271
266
  @next_name = @next_name.next
272
267
  ret
273
268
  end
274
269
 
275
270
  def _next_value
276
- ret = ':' + @next_value
271
+ ret = ":#{@next_value}"
277
272
  @next_value = @next_value.next
278
273
  ret
279
274
  end
@@ -10,7 +10,7 @@ module Aws
10
10
  # attempt to perform an operation against the remote end, if you have not
11
11
  # already configured a client. As such, please read and understand the
12
12
  # documentation in the AWS SDK for Ruby around
13
- # {http://docs.aws.amazon.com/sdkforruby/api/index.html#Configuration configuration}
13
+ # {http://docs.aws.amazon.com/sdk-for-ruby/v3/api/index.html#Configuration configuration}
14
14
  # to ensure you understand how default configuration behavior works. When
15
15
  # in doubt, call this method to ensure your client is configured the way
16
16
  # you want it to be configured.
@@ -26,12 +26,12 @@ module Aws
26
26
  # own pre-configured client.
27
27
  def configure_client(opts = {})
28
28
  # rubocop:disable Style/RedundantSelf
29
- if self.class != Module && Aws::Record.extends_record?(self) && opts.empty? &&
30
- self.superclass.instance_variable_get('@dynamodb_client')
31
- @dynamodb_client = self.superclass.instance_variable_get('@dynamodb_client')
32
- else
33
- @dynamodb_client = _build_client(opts)
34
- end
29
+ @dynamodb_client = if self.class != Module && Aws::Record.extends_record?(self) && opts.empty? &&
30
+ self.superclass.instance_variable_get('@dynamodb_client')
31
+ self.superclass.instance_variable_get('@dynamodb_client')
32
+ else
33
+ _build_client(opts)
34
+ end
35
35
  # rubocop:enable Style/RedundantSelf
36
36
  end
37
37
 
@@ -203,11 +203,9 @@ module Aws
203
203
 
204
204
  record = self.class.find(primary_key)
205
205
 
206
- if record.present?
207
- @data = record.instance_variable_get('@data')
208
- else
209
- raise Errors::NotFound, 'No record found'
210
- end
206
+ raise Errors::NotFound, 'No record found' unless record.present?
207
+
208
+ @data = record.instance_variable_get('@data')
211
209
 
212
210
  clean!
213
211
 
@@ -258,8 +256,6 @@ module Aws
258
256
  end
259
257
 
260
258
  # @private
261
- #
262
- # @override save(*)
263
259
  def save(*)
264
260
  super.tap { clean! }
265
261
  end
@@ -268,15 +264,11 @@ module Aws
268
264
  private
269
265
 
270
266
  # @private
271
- #
272
- # @override build_item_from_resp(*)
273
267
  def build_item_from_resp(*)
274
268
  super.tap(&:clean!)
275
269
  end
276
270
 
277
271
  # @private
278
- #
279
- # @override define_attr_methods(*)
280
272
  def _define_attr_methods(name)
281
273
  super.tap do
282
274
  define_method("#{name}_dirty?") do
@@ -16,7 +16,17 @@ module Aws
16
16
  class NotFound < RecordError; end
17
17
 
18
18
  # Raised when a conditional write fails.
19
- class ConditionalWriteFailed < RecordError; end
19
+ # Provides access to the original ConditionalCheckFailedException error
20
+ # which may have item data if the return values option was used.
21
+ class ConditionalWriteFailed < RecordError
22
+ def initialize(message, original_error)
23
+ @original_error = original_error
24
+ super(message)
25
+ end
26
+
27
+ # @return [Aws::DynamoDB::Errors::ConditionalCheckFailedException]
28
+ attr_reader :original_error
29
+ end
20
30
 
21
31
  # Raised when a validation hook call to +:valid?+ fails.
22
32
  class ValidationError < RecordError; end
@@ -25,14 +25,13 @@ module Aws
25
25
  # @return [Enumerable<Aws::Record>] an enumeration over the results of
26
26
  # your query or scan request. These results are automatically converted
27
27
  # into items on your behalf.
28
- def each
28
+ def each(&block)
29
29
  return enum_for(:each) unless block_given?
30
+
30
31
  items.each_page do |page|
31
32
  @last_evaluated_key = page.last_evaluated_key
32
33
  items_array = _build_items_from_response(page.items, @model)
33
- items_array.each do |item|
34
- yield item
35
- end
34
+ items_array.each(&block)
36
35
  end
37
36
  end
38
37
 
@@ -84,6 +83,7 @@ module Aws
84
83
  items.each do |item|
85
84
  model_class = @model_filter ? @model_filter.call(item) : model
86
85
  next unless model_class
86
+
87
87
  record = model_class.new
88
88
  data = record.instance_variable_get('@data')
89
89
  model_class.attributes.attributes.each do |name, attr|
@@ -97,7 +97,7 @@ module Aws
97
97
  end
98
98
 
99
99
  def items
100
- @_items ||= @client.send(@search_method, @search_params)
100
+ @items ||= @client.send(@search_method, @search_params)
101
101
  end
102
102
  end
103
103
  end
@@ -47,11 +47,11 @@ module Aws
47
47
  @model_attributes.attributes.each_key do |name|
48
48
  populate_default_values
49
49
  value = get_attribute(name)
50
- if @track_mutations
51
- @clean_copies[name] = _deep_copy(value)
52
- else
53
- @clean_copies[name] = value
54
- end
50
+ @clean_copies[name] = if @track_mutations
51
+ _deep_copy(value)
52
+ else
53
+ value
54
+ end
55
55
  end
56
56
  end
57
57
 
@@ -80,7 +80,7 @@ module Aws
80
80
  end
81
81
 
82
82
  def dirty?
83
- dirty.empty? ? false : true
83
+ !dirty.empty?
84
84
  end
85
85
 
86
86
  def rollback_attribute!(name)
@@ -109,11 +109,10 @@ module Aws
109
109
 
110
110
  def populate_default_values
111
111
  @model_attributes.attributes.each do |name, attribute|
112
- unless (default_value = attribute.default_value).nil?
113
- if @data[name].nil? && @data[name].nil?
114
- @data[name] = default_value
115
- end
116
- end
112
+ next if (default_value = attribute.default_value).nil?
113
+ next unless @data[name].nil?
114
+
115
+ @data[name] = default_value
117
116
  end
118
117
  end
119
118