Class: Aws::Resources::Collection

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Includes:
Enumerable, Enumerable[T]
Defined in:
lib/aws-sdk-core/resources/collection.rb,
sig/aws-sdk-core/resources/collection.rbs

Instance Method Summary collapse

Methods included from Deprecations

deprecated

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.

Options Hash (options):

  • :limit (Integer)
  • :size (Integer)


14
15
16
17
18
# File 'lib/aws-sdk-core/resources/collection.rb', line 14

def initialize(batches, options = {})
  @batches = batches
  @limit = options[:limit]
  @size = options[: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.

Deprecated.


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

#batchesObject

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.

Deprecated.


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

#eachEnumerator[T, untyped] #eachEnumerator[T, untyped]

Yields:

Yield Parameters:

  • arg0 (T)

Yield Returns:

  • (Object)


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

#firstT? #first(arg0) ⇒ self



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

#sizeInteger? Also known as: length



23
24
25
# File 'lib/aws-sdk-core/resources/collection.rb', line 23

def size
  @size
end