Class: BitbucketServer::Paginator

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

Constant Summary collapse

PAGE_LENGTH =

Should be kept in-sync with BITBUCKET_SERVER_PAGE_LENGTH in app/assets/javascripts/import_entities/constants.js

25

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, url, type, page_offset: 0, limit: nil) ⇒ Paginator

Returns a new instance of Paginator.



10
11
12
13
14
15
16
17
18
# File 'lib/bitbucket_server/paginator.rb', line 10

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

Instance Attribute Details

#page_offsetObject (readonly)

Returns the value of attribute page_offset.



8
9
10
# File 'lib/bitbucket_server/paginator.rb', line 8

def page_offset
  @page_offset
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/bitbucket_server/paginator.rb', line 29

def has_next_page?
  page.nil? || page.next?
end

#itemsObject

Raises:

  • (StopIteration)


20
21
22
23
24
25
26
27
# File 'lib/bitbucket_server/paginator.rb', line 20

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

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