Sha256: ac077865adeaeb40e85f5a0428602441ceecda4b0593924c29a5cd544d128559

Contents?: true

Size: 473 Bytes

Versions: 8

Compression:

Stored size: 473 Bytes

Contents

module Braintree
  class PaginatedCollection
    include Enumerable

    def initialize(&block)
      @next_page_block = block
    end

    def each(&block)
      current_page = 0
      total_items = 0

      loop do
        current_page += 1

        result = @next_page_block.call(current_page)
        total_items = result.total_items

        result.current_page.each(&block)

        break if current_page * result.page_size >= total_items
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
braintree-4.23.0 lib/braintree/paginated_collection.rb
braintree-4.22.0 lib/braintree/paginated_collection.rb
braintree-4.21.0 lib/braintree/paginated_collection.rb
braintree-4.20.0 lib/braintree/paginated_collection.rb
braintree-4.19.0 lib/braintree/paginated_collection.rb
braintree-4.18.0 lib/braintree/paginated_collection.rb
braintree-4.17.0 lib/braintree/paginated_collection.rb
braintree-4.16.0 lib/braintree/paginated_collection.rb