Class: GH::Pagination::Paginated

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/gh/pagination.rb

Instance Method Summary collapse

Constructor Details

#initialize(page, url, gh) ⇒ Paginated



8
9
10
11
12
# File 'lib/gh/pagination.rb', line 8

def initialize(page, url, gh)
  @page = page
  @next_url = url
  @gh = gh
end

Instance Method Details

#[](value) ⇒ Object

Raises:

  • (TypeError)


25
26
27
28
29
30
# File 'lib/gh/pagination.rb', line 25

def [](value)
  raise TypeError, "index has to be an Integer, got #{value.class}" unless value.is_a? Integer
  return @page[value] if value < @page.size

  next_page[value - @page.size]
end

#each(&block) ⇒ Object



14
15
16
17
18
19
# File 'lib/gh/pagination.rb', line 14

def each(&block)
  return enum_for(:each) unless block

  @page.each(&block)
  next_page.each(&block)
end

#headersObject



36
37
38
# File 'lib/gh/pagination.rb', line 36

def headers
  @page.headers
end

#inspectObject



21
22
23
# File 'lib/gh/pagination.rb', line 21

def inspect
  "[#{first.inspect}, ...]"
end

#to_aryObject



32
33
34
# File 'lib/gh/pagination.rb', line 32

def to_ary
  to_a # replace with better implementation (use in_parallel)
end