class Aws::Resources::Collection
Public Class Methods
new(operation, options)
click to toggle source
@param [HasManyOperation] operation @option (see HasManyOperation#call) @api private
# File lib/aws-sdk-resources/collection.rb, line 10 def initialize(operation, options) @operation = operation @options = options end
Public Instance Methods
batches(&block)
click to toggle source
@api private @return [Enumerator<Batch>]
# File lib/aws-sdk-resources/collection.rb, line 26 def batches(&block) @operation.batches(@options) end
each(&block)
click to toggle source
@return [Enumerator<Resource>]
# File 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)
click to toggle source
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
@return [Resource, Batch]
# File 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
inspect()
click to toggle source
@api private
# File lib/aws-sdk-resources/collection.rb, line 84 def inspect parts = {} parts[:type] = resource_class.name parts[:limit] = @options[:limit] parts[:params] = @options[:params] || {} parts = parts.inject("") {|s,(k,v)| s << " #{k}=#{v.inspect}" } ['#<', self.class.name, parts, '>'].join end
limit(limit)
click to toggle source
Specifies the maximum number of items to enumerate.
collection.limit(10).each do |resource| # yields at most 10 times end
@param [Integer] limit The maximum number of items to yield
via {#each} or {#batches}.
@return [Collection]
# File lib/aws-sdk-resources/collection.rb, line 39 def limit(limit) self.class.new(@operation, @options.merge(limit: limit)) end
method_missing(method_name, *args, &block)
click to toggle source
@api private
Calls superclass method
# File lib/aws-sdk-resources/collection.rb, line 73 def method_missing(method_name, *args, &block) if respond_to?(method_name) batches.each do |batch| batch.send(method_name, *args, &block) end else super end end
respond_to?(method_name, *args)
click to toggle source
@api private
Calls superclass method
# File lib/aws-sdk-resources/collection.rb, line 64 def respond_to?(method_name, *args) if resource_class.batch_operation_names.include?(method_name.to_sym) true else super end end
Private Instance Methods
limit_key()
click to toggle source
@api private
# File lib/aws-sdk-resources/collection.rb, line 96 def limit_key @operation.limit_key end
resource_class()
click to toggle source
# File lib/aws-sdk-resources/collection.rb, line 100 def resource_class @operation.builder.resource_class end