Class: BitbucketServer::Paginator

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

Constant Summary collapse

PAGE_LENGTH =
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.



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

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.



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

def page_offset
  @page_offset
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


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

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

#itemsObject

Raises:

  • (StopIteration)


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

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

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