Class: Bitbucket::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/bitbucket/paginator.rb

Constant Summary collapse

PAGE_LENGTH =

The minimum length is 10 and the maximum is 100.

50

Instance Method Summary collapse

Constructor Details

#initialize(connection, url, type, page_number: nil, limit: nil, after_cursor: nil) ⇒ Paginator

Returns a new instance of Paginator.



7
8
9
10
11
12
13
14
15
# File 'lib/bitbucket/paginator.rb', line 7

def initialize(connection, url, type, page_number: nil, limit: nil, after_cursor: nil)
  @connection = connection
  @type = type
  @url = url
  @page_number = page_number
  @limit = limit
  @after_cursor = after_cursor
  @total = 0
end

Instance Method Details

#itemsObject

Raises:

  • (StopIteration)


17
18
19
20
21
22
23
24
# File 'lib/bitbucket/paginator.rb', line 17

def items
  raise StopIteration if over_limit?
  raise StopIteration unless has_next_page?

  @page = fetch_next_page
  @total += @page.items.count
  @page.items
end

#page_infoObject



26
27
28
29
30
31
32
# File 'lib/bitbucket/paginator.rb', line 26

def page_info
  {
    has_next_page: page.attrs[:next].present?,
    start_cursor: @after_cursor,
    end_cursor: next_page_cursor
  }
end