Class: Aws::Record::BatchRead
- Inherits:
-
Object
- Object
- Aws::Record::BatchRead
- Includes:
- Enumerable
- Defined in:
- lib/aws-record/record/batch_read.rb
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Indicates if all item keys have been processed.
-
#each {|item| ... } ⇒ Enumerable<BatchRead>
Provides an enumeration of the results from the
batch_get_item
request and handles pagination. -
#execute! ⇒ Array
Perform a
batch_get_item
request. -
#find(klass, key = {}) ⇒ Object
Append the item keys to a batch read request.
-
#initialize(opts = {}) ⇒ BatchRead
constructor
A new instance of BatchRead.
-
#items ⇒ Array
Returns an array of modeled items.
Constructor Details
#initialize(opts = {}) ⇒ BatchRead
Returns a new instance of BatchRead.
13 14 15 |
# File 'lib/aws-record/record/batch_read.rb', line 13 def initialize(opts = {}) @client = opts[:client] end |
Instance Method Details
#complete? ⇒ Boolean
Indicates if all item keys have been processed.
See Aws::Record::Batch.read for example usage.
78 79 80 |
# File 'lib/aws-record/record/batch_read.rb', line 78 def complete? unprocessed_keys.none? end |
#each {|item| ... } ⇒ Enumerable<BatchRead>
Provides an enumeration of the results from the batch_get_item
request and handles pagination.
Any pending item keys will be automatically processed and be added to the #items.
See Aws::Record::Batch.read for example usage.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/aws-record/record/batch_read.rb', line 63 def each(&block) return enum_for(:each) unless block_given? @items.each(&block) until complete? new_items = execute! new_items.each(&block) end end |
#execute! ⇒ Array
Perform a batch_get_item
request.
This method processes the first 100 item keys and returns an array of new modeled items.
See Aws::Record::Batch.read for example usage.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aws-record/record/batch_read.rb', line 39 def execute! operation_keys = unprocessed_keys[0..BATCH_GET_ITEM_LIMIT - 1] @unprocessed_keys = unprocessed_keys[BATCH_GET_ITEM_LIMIT..-1] || [] operations = build_operations(operation_keys) result = @client.batch_get_item(request_items: operations) new_items = build_items(result.responses) items.concat(new_items) update_unprocessed_keys(result.unprocessed_keys) unless result.unprocessed_keys.nil? new_items end |
#find(klass, key = {}) ⇒ Object
Append the item keys to a batch read request.
See Aws::Record::Batch.read for example usage.
26 27 28 29 30 |
# File 'lib/aws-record/record/batch_read.rb', line 26 def find(klass, key = {}) unprocessed_key = format_unprocessed_key(klass, key) store_unprocessed_key(klass, unprocessed_key) store_item_class(klass, unprocessed_key) end |
#items ⇒ Array
Returns an array of modeled items. The items are marshaled into classes used in #find method. These items will be unordered since DynamoDB does not return items in any particular order.
See Aws::Record::Batch.read for example usage.
87 88 89 |
# File 'lib/aws-record/record/batch_read.rb', line 87 def items @items ||= [] end |