Sha256: 37c08fb4ebea8fd5b7ca6a99d9281e9ae9fb51f0fab0ece98be32c2a8e894ae6

Contents?: true

Size: 1.69 KB

Versions: 163

Compression:

Stored size: 1.69 KB

Contents

require 'jmespath'

module Aws
  # @api private
  class Pager

    # @option options [required, Hash<JMESPath,JMESPath>] :tokens
    # @option options [String<JMESPath>] :limit_key
    # @option options [String<JMESPath>] :more_results
    def initialize(options)
      @tokens = options.fetch(:tokens)
      @limit_key = options.fetch(:limit_key, nil)
      @more_results = options.fetch(:more_results, nil)
    end

    # @return [Symbol, nil]
    attr_reader :limit_key

    # @param [Seahorse::Client::Response] response
    # @return [Hash]
    def next_tokens(response)
      @tokens.each.with_object({}) do |(source, target), next_tokens|
        value = JMESPath.search(source, response.data)
        next_tokens[target.to_sym] = value unless empty_value?(value)
      end
    end

    # @api private
    def prev_tokens(response)
      @tokens.each.with_object({}) do |(_, target), tokens|
        value = JMESPath.search(target, response.context.params)
        tokens[target.to_sym] = value unless empty_value?(value)
      end
    end

    # @param [Seahorse::Client::Response] response
    # @return [Boolean]
    def truncated?(response)
      if @more_results
        JMESPath.search(@more_results, response.data)
      else
        next_t = next_tokens(response)
        prev_t = prev_tokens(response)
        !(next_t.empty? || next_t == prev_t)
      end
    end

    private

    def empty_value?(value)
      value.nil? || value == '' || value == [] || value == {}
    end

    class NullPager

      # @return [nil]
      attr_reader :limit_key

      def next_tokens
        {}
      end

      def prev_tokens
        {}
      end

      def truncated?(response)
        false
      end

    end
  end
end

Version data entries

163 entries across 163 versions & 1 rubygems

Version Path
aws-sdk-core-3.100.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.99.2 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.99.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.99.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.98.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.97.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.97.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.96.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.96.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.95.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.94.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.94.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.93.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.92.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.91.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.91.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.90.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.90.0 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.89.1 lib/aws-sdk-core/pager.rb
aws-sdk-core-3.89.0 lib/aws-sdk-core/pager.rb