Class: Aws::Resources::Collection
- Inherits:
-
Object
- Object
- Aws::Resources::Collection
- Extended by:
- Deprecations
- Includes:
- Enumerable
- Defined in:
- lib/aws-sdk-core/resources/collection.rb
Instance Method Summary collapse
- #[](index) ⇒ Object deprecated private Deprecated.
- #batches ⇒ Object deprecated private Deprecated.
- #each(&block) ⇒ Enumerator<Band>
- #first(count = nil) ⇒ Resource, Collection
-
#initialize(batches, options = {}) ⇒ Collection
constructor
private
A new instance of Collection.
-
#limit(limit) ⇒ Collection
Returns a new collection that will enumerate a limited number of items.
-
#size ⇒ Integer?
(also: #length)
Returns the size of this collection if known, returns ‘nil` when an API call is necessary to enumerate items in this collection.
Methods included from Deprecations
Constructor Details
#initialize(batches, options = {}) ⇒ Collection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Collection.
14 15 16 17 18 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 14 def initialize(batches, = {}) @batches = batches @limit = [:limit] @size = [:size] end |
Instance Method Details
#[](index) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 40 def [](index) if @size @batches[0][index] else raise "unable to index into a lazy loaded collection" end end |
#batches ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 33 34 35 36 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 30 def batches ::Enumerator.new do |y| batch_enum.each do |batch| y << self.class.new([batch], size: batch.size) end end end |
#each(&block) ⇒ Enumerator<Band>
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 50 def each(&block) enum = ::Enumerator.new do |y| batch_enum.each do |batch| batch.each do |band| y.yield(band) end end end enum.each(&block) if block enum end |
#first(count = nil) ⇒ Resource, Collection
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 64 def first(count = nil) if count items = limit(count).to_a self.class.new([items], size: items.size) else begin each.next rescue StopIteration nil end end end |
#limit(limit) ⇒ Collection
Returns a new collection that will enumerate a limited number of items.
collection.limit(10).each do |band|
# yields at most 10 times
end
85 86 87 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 85 def limit(limit) Collection.new(@batches, limit: limit) end |
#size ⇒ Integer? Also known as: length
Returns the size of this collection if known, returns ‘nil` when an API call is necessary to enumerate items in this collection.
23 24 25 |
# File 'lib/aws-sdk-core/resources/collection.rb', line 23 def size @size end |