Class: Dynamoid::AdapterPlugin::AwsSdkV3::BatchGetItem::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb

Overview

Helper class to work with response

Instance Method Summary collapse

Constructor Details

#initialize(api_response) ⇒ Response

Returns a new instance of Response.



78
79
80
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 78

def initialize(api_response)
  @api_response = api_response
end

Instance Method Details

#items_grouped_by_tableObject



101
102
103
104
105
106
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 101

def items_grouped_by_table
  # data[:responses] is a Hash[table_name -> items]
  @api_response.data[:responses].transform_values do |items|
    items.map(&method(:item_to_hash))
  end
end

#successful_partially?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 82

def successful_partially?
  @api_response.unprocessed_keys.present?
end

#unprocessed_ids(table) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb', line 86

def unprocessed_ids(table)
  # unprocessed_keys Hash contains as values instances of
  # Aws::DynamoDB::Types::KeysAndAttributes
  @api_response.unprocessed_keys[table.name].keys.map do |h|
    # If a table has a composite primary key then we need to return an array
    # of [hash key, range key]. Otherwise just return hash key's
    # value.
    if table.range_key.nil?
      h[table.hash_key.to_s]
    else
      [h[table.hash_key.to_s], h[table.range_key.to_s]]
    end
  end
end