Class: Braintree::PaginatedCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/braintree/paginated_collection.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ PaginatedCollection

:nodoc:


5
6
7
# File 'lib/braintree/paginated_collection.rb', line 5

def initialize(&block) # :nodoc:
  @next_page_block = block
end

Instance Method Details

#each(&block) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/braintree/paginated_collection.rb', line 9

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