Class: Aws::Record::ItemCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/aws-record/record/item_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(search_method, search_params, model, client) ⇒ ItemCollection

Returns a new instance of ItemCollection



19
20
21
22
23
24
# File 'lib/aws-record/record/item_collection.rb', line 19

def initialize(search_method, search_params, model, client)
  @search_method = search_method
  @search_params = search_params
  @model = model
  @client = client
end

Instance Method Details

#each(&block) ⇒ Enumerable<Aws::Record>

Provides an enumeration of the results of a query or scan operation on your table, automatically converted into item classes.

WARNING: This will enumerate over your entire partition in the case of query, and over your entire table in the case of scan, save for key and filter expressions used. This means that enumerable operations that iterate over the full result set could make many network calls, or use a lot of memory to build response objects. Use with caution.

Returns:

  • (Enumerable<Aws::Record>)

    an enumeration over the results of your query or scan request. These results are automatically converted into items on your behalf.



38
39
40
41
42
43
44
45
46
# File 'lib/aws-record/record/item_collection.rb', line 38

def each(&block)
  return enum_for(:each) unless block_given?
  items.each_page do |page|
    items_array = _build_items_from_response(page.items, @model)
    items_array.each do |item|
      yield item
    end
  end
end

#empty?Boolean

Checks if the query/scan result is completely blank.

WARNING: This can and will query your entire partition, or scan your entire table, if no results are found. Especially if your table is large, use this with extreme caution.

Returns:

  • (Boolean)

    true if the query/scan result is empty, false otherwise.



56
57
58
59
60
61
# File 'lib/aws-record/record/item_collection.rb', line 56

def empty?
  items.each_page do |page|
    return false if !page.items.empty?
  end
  true
end