Class: Aws::Resources::Batch
- Inherits:
-
Object
- Object
- Aws::Resources::Batch
- Includes:
- Enumerable
- Defined in:
- lib/aws-sdk-resources/batch.rb
Overview
A batch provides array like access to a list of resources. Batches also provide the ability to invoke certain operations against the entire batch.
## Getting a Batch
You should normally not need to construct a batch. Anywhere a list of resources is returned, they are returned as a batch:
# security_groups is a batch
security_groups = ec2.instance('i-12345678').security_groups
When the possible number of resources is unknown or large, the resources will be returned in a collection. Collections can enumerate individual resources or batches. They manage paging over the AWS request/responses to produce batches.
# objects is a collection
objects = s3.bucket('aws-sdk').objects
You can invoke batch operations against collections and they will invoke them on each batch.
# delete all objects in this bucket in batches of 1k
objects = s3.bucket('aws-sdk').objects
objects.delete
## Batch Operations
Batches provide operations that operate on the entire batch. These operations are only defined for resources where the AWS API accepts multiple inputs. This means a batch operation for n resources will only make one request.
Resource classes document each of their own batch operations. See S3::Object for an example.
Instance Attribute Summary collapse
- #resource_class ⇒ Class<Resource> readonly
- #response ⇒ Seahorse::Client::Response? readonly
- #size ⇒ Integer (also: #count) readonly
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Resource
-
#each(&block) ⇒ Object
Yields each resource of the batch, one at a time.
- #empty? ⇒ Boolean
- #first(count = nil) ⇒ Resource, Batch
-
#initialize(resource_class, resources, options = {}) ⇒ Batch
constructor
A new instance of Batch.
- #inspect ⇒ Object private
- #method_missing(method_name, *args, &block) ⇒ Object private
- #respond_to?(method_name, *args) ⇒ Boolean private
Constructor Details
#initialize(resource_class, resources, options = {}) ⇒ Batch
Returns a new instance of Batch.
47 48 49 50 51 52 53 |
# File 'lib/aws-sdk-resources/batch.rb', line 47 def initialize(resource_class, resources, = {}) @resource_class = resource_class @resources = resources @response = [:response] @size = resources.size @options = end |
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.
109 110 111 112 113 114 115 |
# File 'lib/aws-sdk-resources/batch.rb', line 109 def method_missing(method_name, *args, &block) if respond_to?(method_name) invoke_batch_operation(method_name, args, block) unless empty? else super end end |
Instance Attribute Details
#resource_class ⇒ Class<Resource> (readonly)
56 57 58 |
# File 'lib/aws-sdk-resources/batch.rb', line 56 def resource_class @resource_class end |
#response ⇒ Seahorse::Client::Response? (readonly)
59 60 61 |
# File 'lib/aws-sdk-resources/batch.rb', line 59 def response @response end |
#size ⇒ Integer (readonly) Also known as: count
62 63 64 |
# File 'lib/aws-sdk-resources/batch.rb', line 62 def size @size end |
Class Method Details
.validate_batch_args!(args) ⇒ 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.
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/aws-sdk-resources/batch.rb', line 128 def validate_batch_args!(args) case args.count when 0 when 1 unless Hash === args.first raise ArgumentError, "expected options to be a hash" end else raise ArgumentError, "wrong number of arguments, expected 0 or 1" end end |
Instance Method Details
#[](index) ⇒ Resource
68 69 70 |
# File 'lib/aws-sdk-resources/batch.rb', line 68 def [](index) @resources[index] end |
#each(&block) ⇒ Object
Yields each resource of the batch, one at a time.
73 74 75 76 77 |
# File 'lib/aws-sdk-resources/batch.rb', line 73 def each(&block) enum = @resources.to_enum enum.each(&block) if block_given? enum end |
#empty? ⇒ Boolean
90 91 92 |
# File 'lib/aws-sdk-resources/batch.rb', line 90 def empty? @resources.empty? end |
#first(count = nil) ⇒ Resource, Batch
81 82 83 84 85 86 87 |
# File 'lib/aws-sdk-resources/batch.rb', line 81 def first(count = nil) if count self.class.new(@resource_class, @resources.first(count), @options) else @resources.first end end |
#inspect ⇒ 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.
95 96 97 |
# File 'lib/aws-sdk-resources/batch.rb', line 95 def inspect "#<#{self.class.name} resources=#{@resources.inspect}>" end |
#respond_to?(method_name, *args) ⇒ Boolean
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.
100 101 102 103 104 105 106 |
# File 'lib/aws-sdk-resources/batch.rb', line 100 def respond_to?(method_name, *args) if @resource_class.batch_operation_names.include?(method_name.to_sym) true else super end end |