Class: Aws::Resources::Collection

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Includes:
Enumerable
Defined in:
lib/aws-sdk-core/resources/collection.rb

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

Parameters:

  • batches (Enumerator<Array>)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

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


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

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.


38
39
40
41
42
43
44
# File 'lib/aws-sdk-core/resources/collection.rb', line 38

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.


28
29
30
31
32
33
34
# File 'lib/aws-sdk-core/resources/collection.rb', line 28

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>

Returns:

  • (Enumerator<Band>)


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/aws-sdk-core/resources/collection.rb', line 48

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

Parameters:

  • count (Integer) (defaults to: nil)

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/aws-sdk-core/resources/collection.rb', line 62

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

Parameters:

  • limit (Integer)

Returns:



83
84
85
# File 'lib/aws-sdk-core/resources/collection.rb', line 83

def limit(limit)
  Collection.new(@batches, limit: limit)
end

#sizeInteger? 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.

Returns:

  • (Integer, nil)

    Returns the size of this collection if known, returns `nil` when an API call is necessary to enumerate items in this collection.



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

def size
  @size
end