Description of changes:
Add #multi_model_filter to BuildableSearch which takes either a passed Proc/lambda or a block. Given the raw item data that model_filter returns the class (or nil to skip) to use for that item.
Example Usage
class Model_A
include Aws::Record
set_table_name(TABLE_NAME)
string_attr :uuid, hash_key: true
string_attr :class_name, range_key: true
string_attr :attr_a
end
class Model_B
include Aws::Record
set_table_name(TABLE_NAME)
string_attr :uuid, hash_key: true
string_attr :class_name, range_key: true
string_attr :attr_b
end
# use multi_model_filter to create a query on TABLE_NAME
items = Model_A.build_scan.multi_model_filter do |raw_item_attributes|
case raw_item_attributes['class_name']
when "A" then Model_A
when "B" then Model_B
else
nil
end
end.complete!
Of note:
This still requires calling complete! on the query which is a little strange. But allows you to pass a lambda/proc was a parameter to multi_model_filter and use it just like any other builder function. (One alternative is to call complete! when a block is passed, but treat a passed parameter as a builder function).
The item data is raw - which means keys are the raw strings from the db (rather than any translated, symbolized names).
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Issue: #107
Description of changes: Add
#multi_model_filter
toBuildableSearch
which takes either a passed Proc/lambda or a block. Given the raw item data thatmodel_filter
returns the class (or nil to skip) to use for that item.Example Usage
Of note:
complete!
on the query which is a little strange. But allows you to pass a lambda/proc was a parameter tomulti_model_filter
and use it just like any other builder function. (One alternative is to call complete! when a block is passed, but treat a passed parameter as a builder function).By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.