Sha256: 47ac8014372618c4bd68ae7b7c84965abf06663ec0751596d302625f83622802

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

# Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

module AWS
  module Core
    module Collection

      # = Collection::WithLimitAndNextToken
      #
      # This module is used by collections where the service may truncate
      # responses but that also accept a upper limit of results to
      # return in a single request.
      #
      # See {AWS::Core::Collection} for documentation on the available
      # methods.
      #
      module WithLimitAndNextToken

        include Model
        include Collection
        include Enumerable

        protected

        def _each_batch options = {}, &block

          limit = _extract_limit(options)
          batch_size = _extract_batch_size(options)
          next_token = _extract_next_token(options)

          total = 0  # count of items yeilded across all batches

          begin

            max = nil
            if limit or batch_size
              max = []
              max << (limit - total) if limit
              max << batch_size if batch_size
              max = max.min
            end

            batch = []
            next_token = _each_item(next_token, max, options.dup) do |item|

              total += 1
              batch << item

            end

            yield(batch)

          end until next_token.nil? or (limit and limit == total)

          next_token

        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
aws-sdk-euca-1.8.5 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.5 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.4 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.3.1 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.3 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.2 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.1.3 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.1.2 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.1.1 lib/aws/core/collection/with_limit_and_next_token.rb
aws-sdk-1.8.1 lib/aws/core/collection/with_limit_and_next_token.rb