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

Class: Aws::Resources::Collection

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

Direct Known Subclasses

AutoScaling::Activity::Collection, AutoScaling::AutoScalingGroup::Collection, AutoScaling::Instance::Collection, AutoScaling::LaunchConfiguration::Collection, AutoScaling::LifecycleHook::Collection, AutoScaling::LoadBalancer::Collection, AutoScaling::NotificationConfiguration::Collection, AutoScaling::ScalingPolicy::Collection, AutoScaling::ScheduledAction::Collection, AutoScaling::Tag::Collection, CloudFormation::Event::Collection, CloudFormation::Stack::Collection, CloudFormation::StackResource::Collection, CloudFormation::StackResourceSummary::Collection, CloudWatch::Alarm::Collection, CloudWatch::Metric::Collection, DynamoDB::Table::Collection, EC2::ClassicAddress::Collection, EC2::DhcpOptions::Collection, EC2::Image::Collection, EC2::Instance::Collection, EC2::InternetGateway::Collection, EC2::KeyPair::Collection, EC2::KeyPairInfo::Collection, EC2::NetworkAcl::Collection, EC2::NetworkInterface::Collection, EC2::NetworkInterfaceAssociation::Collection, EC2::PlacementGroup::Collection, EC2::Route::Collection, EC2::RouteTable::Collection, EC2::RouteTableAssociation::Collection, EC2::SecurityGroup::Collection, EC2::Snapshot::Collection, EC2::Subnet::Collection, EC2::Tag::Collection, EC2::Volume::Collection, EC2::Vpc::Collection, EC2::VpcAddress::Collection, EC2::VpcPeeringConnection::Collection, Glacier::Account::Collection, Glacier::Archive::Collection, Glacier::Job::Collection, Glacier::MultipartUpload::Collection, Glacier::Notification::Collection, Glacier::Vault::Collection, IAM::AccessKey::Collection, IAM::AccessKeyPair::Collection, IAM::AccountPasswordPolicy::Collection, IAM::AccountSummary::Collection, IAM::AssumeRolePolicy::Collection, IAM::CurrentUser::Collection, IAM::Group::Collection, IAM::GroupPolicy::Collection, IAM::InstanceProfile::Collection, IAM::LoginProfile::Collection, IAM::MfaDevice::Collection, IAM::Policy::Collection, IAM::PolicyVersion::Collection, IAM::Role::Collection, IAM::RolePolicy::Collection, IAM::SamlProvider::Collection, IAM::ServerCertificate::Collection, IAM::SigningCertificate::Collection, IAM::User::Collection, IAM::UserPolicy::Collection, IAM::VirtualMfaDevice::Collection, OpsWorks::Layer::Collection, OpsWorks::Stack::Collection, OpsWorks::StackSummary::Collection, Aws::RDS::AccountQuota::Collection, Aws::RDS::Certificate::Collection, Aws::RDS::DBCluster::Collection, Aws::RDS::DBClusterParameterGroup::Collection, Aws::RDS::DBClusterSnapshot::Collection, Aws::RDS::DBEngine::Collection, Aws::RDS::DBEngineVersion::Collection, Aws::RDS::DBInstance::Collection, Aws::RDS::DBLogFile::Collection, Aws::RDS::DBParameterGroup::Collection, Aws::RDS::DBParameterGroupFamily::Collection, Aws::RDS::DBSecurityGroup::Collection, Aws::RDS::DBSnapshot::Collection, Aws::RDS::DBSnapshotAttribute::Collection, Aws::RDS::DBSubnetGroup::Collection, Aws::RDS::Event::Collection, Aws::RDS::EventCategoryMap::Collection, Aws::RDS::EventSubscription::Collection, Aws::RDS::OptionGroup::Collection, Aws::RDS::OptionGroupOption::Collection, Aws::RDS::Parameter::Collection, Aws::RDS::PendingMaintenanceAction::Collection, Aws::RDS::ReservedDBInstance::Collection, Aws::RDS::ReservedDBInstancesOffering::Collection, Aws::RDS::ResourcePendingMaintenanceActionList::Collection, S3::Bucket::Collection, S3::BucketAcl::Collection, S3::BucketCors::Collection, S3::BucketLifecycle::Collection, S3::BucketLogging::Collection, S3::BucketNotification::Collection, S3::BucketPolicy::Collection, S3::BucketRequestPayment::Collection, S3::BucketTagging::Collection, S3::BucketVersioning::Collection, S3::BucketWebsite::Collection, S3::MultipartUpload::Collection, S3::MultipartUploadPart::Collection, S3::Object::Collection, S3::ObjectAcl::Collection, S3::ObjectSummary::Collection, S3::ObjectVersion::Collection, SNS::PlatformApplication::Collection, SNS::PlatformEndpoint::Collection, SNS::Subscription::Collection, SNS::Topic::Collection, SQS::Message::Collection, SQS::Queue::Collection

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Enumerator<Band>

Returns:

  • (Enumerator<Band>)


48
49
50
51
52
53
54
55
56
57
58
# File 'gems/aws-sdk-core/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 'gems/aws-sdk-core/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 'gems/aws-sdk-core/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 'gems/aws-sdk-core/lib/aws-sdk-core/resources/collection.rb', line 21

def size
  @size
end