AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::Resources::Collection

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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ 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.



73
74
75
76
77
78
79
80
81
82
# File 'aws-sdk-resources/lib/aws-sdk-resources/collection.rb', line 73

def method_missing(method_name, *args, &block)
  if respond_to?(method_name)
    Batch.validate_batch_args!(args)
    batches.each do |batch|
      batch.send(method_name, *args, &block)
    end
  else
    super
  end
end

Instance Method Details

#each(&block) ⇒ Enumerator<Resource>

Returns:



16
17
18
19
20
21
22
# File 'aws-sdk-resources/lib/aws-sdk-resources/collection.rb', line 16

def each(&block)
  if block_given?
    batches.each { |batch| batch.each(&block) }
  else
    self
  end
end

#first(count = 1) ⇒ Resource, Batch

Returns the first resource from the collection.

resource = collection.first

If you pass a count, then the first count resources are returned in a single batch. See the resource specific batch documentation for a list of supported batch methods.

resources = collection.first(10)
resources.delete

Returns:



55
56
57
58
59
60
61
# File 'aws-sdk-resources/lib/aws-sdk-resources/collection.rb', line 55

def first(count = 1)
  if count == 1
    limit(1).to_a.first
  else
    Batch.new(resource_class, limit(count).to_a)
  end
end

#limit(limit) ⇒ Collection

Specifies the maximum number of items to enumerate.

collection.limit(10).each do |resource|
  # yields at most 10 times
end

Parameters:

  • limit (Integer)

    The maximum number of items to yield via #each or #batches.

Returns:



39
40
41
# File 'aws-sdk-resources/lib/aws-sdk-resources/collection.rb', line 39

def limit(limit)
  self.class.new(@operation, @options.merge(limit: limit))
end