aws-record 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/aws-record/record/item_operations.rb +38 -7
- data/lib/aws-record/record/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ad49e4e5f6ac03a577a97f00f2312c37dfbe3ed
|
4
|
+
data.tar.gz: f5bf877eb339d5206f24f3c26e78adefdd08ff30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e816d83098562cf009da4c44520605260f22440d6f384fd55c94e30e47b789fa1106cda1b50c4a47fc314ee9b83c254e6e781edb464f46035fb63e42ab347c28
|
7
|
+
data.tar.gz: 6c501354f1de3358c4ee475ad8c8dd017d5e6a9b748af57b570114781d1b614a3f4ba27b9ea3944b2a0c36559ee76586ad2cfb92ae91feb46a9f1a46674aec04
|
@@ -237,21 +237,52 @@ module Aws
|
|
237
237
|
# @raise [Aws::Record::Errors::KeyMissing] if your option parameters do
|
238
238
|
# not include all table keys.
|
239
239
|
def find(opts)
|
240
|
-
key
|
240
|
+
find_with_opts(key: opts)
|
241
|
+
end
|
242
|
+
|
243
|
+
# @example Usage Example
|
244
|
+
# class MyModel
|
245
|
+
# include Aws::Record
|
246
|
+
# integer_attr :id, hash_key: true
|
247
|
+
# string_attr :name, range_key: true
|
248
|
+
# end
|
249
|
+
#
|
250
|
+
# MyModel.find_with_opts(
|
251
|
+
# key: { id: 1, name: "First" },
|
252
|
+
# consistent_read: true
|
253
|
+
# )
|
254
|
+
#
|
255
|
+
# Note that +#find_with_opts+ will pass through all options other than
|
256
|
+
# +:key+ unaltered to the underlying +Aws::DynamoDB::Client#get_item+
|
257
|
+
# request. You should ensure that you have an aws-sdk gem version which
|
258
|
+
# supports the options you are including, and avoid adding options not
|
259
|
+
# recognized by the underlying client to avoid runtime exceptions.
|
260
|
+
#
|
261
|
+
# @param [Hash] opts Options to pass through to the DynamoDB #get_item
|
262
|
+
# request. The +:key+ option is a special case where attributes are
|
263
|
+
# serialized and translated for you similar to the #find method.
|
264
|
+
# @option opts [Hash] :key attribute-value pairs for the key you wish to
|
265
|
+
# search for.
|
266
|
+
# @return [Aws::Record] builds and returns an instance of your model.
|
267
|
+
# @raise [Aws::Record::Errors::KeyMissing] if your option parameters do
|
268
|
+
# not include all table keys.
|
269
|
+
def find_with_opts(opts)
|
270
|
+
key = opts.delete(:key)
|
271
|
+
request_key = {}
|
241
272
|
@keys.keys.each_value do |attr_sym|
|
242
|
-
unless
|
273
|
+
unless key[attr_sym]
|
243
274
|
raise Errors::KeyMissing.new(
|
244
|
-
"Missing required key #{attr_sym} in #{
|
275
|
+
"Missing required key #{attr_sym} in #{key}"
|
245
276
|
)
|
246
277
|
end
|
247
278
|
attr_name = attributes.storage_name_for(attr_sym)
|
248
|
-
|
249
|
-
serialize(
|
279
|
+
request_key[attr_name] = attributes.attribute_for(attr_sym).
|
280
|
+
serialize(key[attr_sym])
|
250
281
|
end
|
251
282
|
request_opts = {
|
252
283
|
table_name: table_name,
|
253
|
-
key:
|
254
|
-
}
|
284
|
+
key: request_key
|
285
|
+
}.merge(opts)
|
255
286
|
resp = dynamodb_client.get_item(request_opts)
|
256
287
|
if resp.item.nil?
|
257
288
|
nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-resources
|