Class: Dynamoid::AdapterPlugin::AwsSdkV3::BatchGetItem
- Inherits:
-
Object
- Object
- Dynamoid::AdapterPlugin::AwsSdkV3::BatchGetItem
- Defined in:
- lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb
Overview
Defined Under Namespace
Classes: Response
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#tables_with_ids ⇒ Object
readonly
Returns the value of attribute tables_with_ids.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(client, tables_with_ids, options = {}) ⇒ BatchGetItem
constructor
A new instance of BatchGetItem.
Constructor Details
#initialize(client, tables_with_ids, options = {}) ⇒ BatchGetItem
Returns a new instance of BatchGetItem.
12 13 14 15 16 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 12 def initialize(client, tables_with_ids, = {}) @client = client @tables_with_ids = tables_with_ids @options = end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 10 def client @client end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 10 def @options end |
#tables_with_ids ⇒ Object (readonly)
Returns the value of attribute tables_with_ids.
10 11 12 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 10 def tables_with_ids @tables_with_ids end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 18 def call results = {} tables_with_ids.each do |table, ids| if ids.blank? results[table.name] = [] next end ids = Array(ids).dup while ids.present? batch = ids.shift(Dynamoid::Config.batch_size) request = build_request(table, batch) api_response = client.batch_get_item(request) response = Response.new(api_response) if block_given? # return batch items as a result batch_results = Hash.new([].freeze) batch_results.update(response.items_grouped_by_table) yield(batch_results, response.successful_partially?) else # collect all the batches to return at the end results.update(response.items_grouped_by_table) { |_, its1, its2| its1 + its2 } end if response.successful_partially? ids += response.unprocessed_ids(table) end end end results unless block_given? end |