aws-record 2.4.1 → 2.5.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c259c949c94ace6740e388e2e37fa10d08d13c8b2b79cfd7d10652bc00fa6e34
|
4
|
+
data.tar.gz: 52bcb1b830d09018a77db7e6d19fdabe78d7cc5a324245de6de39fa66ae8231e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b71b3595ada2889fd0120c705d6b901b343b2e72bbb834223e291b7bd624d7b800f831612ccf1df4e4b29fdf478f091c05617375a1e944b0d0a8248ac85df08b
|
7
|
+
data.tar.gz: c30b07acabd6604a55468f3ea1dfea5ff1fdaee3aa199d15c594f3864d54ffc7ba3339e86606c881a2c19843fad780f72638f768ebcda0e8ba991e5e77f9e134
|
@@ -178,6 +178,50 @@ module Aws
|
|
178
178
|
self
|
179
179
|
end
|
180
180
|
|
181
|
+
# Allows you to define a callback that will determine the model class
|
182
|
+
# to be used for each item, allowing queries to return an ItemCollection
|
183
|
+
# with mixed models. The provided block must return the model class based on
|
184
|
+
# any logic on the raw item attributes or `nil` if no model applies and
|
185
|
+
# the item should be skipped. Note: The block only has access to raw item
|
186
|
+
# data so attributes must be accessed using their names as defined in the
|
187
|
+
# table, not as the symbols defined in the model class(s).
|
188
|
+
#
|
189
|
+
# @example Scan with heterogeneous results:
|
190
|
+
# # Example model classes
|
191
|
+
# class Model_A
|
192
|
+
# include Aws::Record
|
193
|
+
# set_table_name(TABLE_NAME)
|
194
|
+
#
|
195
|
+
# string_attr :uuid, hash_key: true
|
196
|
+
# string_attr :class_name, range_key: true
|
197
|
+
#
|
198
|
+
# string_attr :attr_a
|
199
|
+
# end
|
200
|
+
#
|
201
|
+
# class Model_B
|
202
|
+
# include Aws::Record
|
203
|
+
# set_table_name(TABLE_NAME)
|
204
|
+
#
|
205
|
+
# string_attr :uuid, hash_key: true
|
206
|
+
# string_attr :class_name, range_key: true
|
207
|
+
#
|
208
|
+
# string_attr :attr_b
|
209
|
+
# end
|
210
|
+
#
|
211
|
+
# # use multi_model_filter to create a query on TABLE_NAME
|
212
|
+
# items = Model_A.build_scan.multi_model_filter do |raw_item_attributes|
|
213
|
+
# case raw_item_attributes['class_name']
|
214
|
+
# when "A" then Model_A
|
215
|
+
# when "B" then Model_B
|
216
|
+
# else
|
217
|
+
# nil
|
218
|
+
# end
|
219
|
+
# end.complete!
|
220
|
+
def multi_model_filter(proc = nil, &block)
|
221
|
+
@params[:model_filter] = proc || block
|
222
|
+
self
|
223
|
+
end
|
224
|
+
|
181
225
|
# You must call this method at the end of any query or scan you build.
|
182
226
|
#
|
183
227
|
# @return [Aws::Record::ItemCollection] The item collection lazy
|
@@ -19,6 +19,7 @@ module Aws
|
|
19
19
|
def initialize(search_method, search_params, model, client)
|
20
20
|
@search_method = search_method
|
21
21
|
@search_params = search_params
|
22
|
+
@model_filter = @search_params.delete(:model_filter)
|
22
23
|
@model = model
|
23
24
|
@client = client
|
24
25
|
end
|
@@ -91,9 +92,11 @@ module Aws
|
|
91
92
|
def _build_items_from_response(items, model)
|
92
93
|
ret = []
|
93
94
|
items.each do |item|
|
94
|
-
|
95
|
+
model_class = @model_filter ? @model_filter.call(item) : model
|
96
|
+
next unless model_class
|
97
|
+
record = model_class.new
|
95
98
|
data = record.instance_variable_get("@data")
|
96
|
-
|
99
|
+
model_class.attributes.attributes.each do |name, attr|
|
97
100
|
data.set_attribute(name, attr.extract(item))
|
98
101
|
end
|
99
102
|
data.clean!
|
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: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amazon Web Services
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-dynamodb
|
@@ -26,7 +26,8 @@ dependencies:
|
|
26
26
|
version: '1.18'
|
27
27
|
description: Provides an object mapping abstraction for Amazon DynamoDB.
|
28
28
|
email:
|
29
|
-
-
|
29
|
+
- mamuller@amazon.com
|
30
|
+
- alexwoo@amazon.com
|
30
31
|
executables: []
|
31
32
|
extensions: []
|
32
33
|
extra_rdoc_files: []
|
@@ -65,7 +66,7 @@ homepage: http://github.com/aws/aws-sdk-ruby-record
|
|
65
66
|
licenses:
|
66
67
|
- Apache 2.0
|
67
68
|
metadata: {}
|
68
|
-
post_install_message:
|
69
|
+
post_install_message:
|
69
70
|
rdoc_options: []
|
70
71
|
require_paths:
|
71
72
|
- lib
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
84
|
rubygems_version: 3.0.3
|
84
|
-
signing_key:
|
85
|
+
signing_key:
|
85
86
|
specification_version: 4
|
86
87
|
summary: AWS Record library for Amazon DynamoDB
|
87
88
|
test_files: []
|