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

Returns a new instance of Paginated.



6
7
8
# File 'lib/gh/pagination.rb', line 6

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

Instance Method Details

#[](value) ⇒ Object

Raises:

  • (TypeError)


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

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



10
11
12
13
14
# File 'lib/gh/pagination.rb', line 10

def each(&block)
  return enum_for(:each) unless block
  @page.each(&block)
  next_page.each(&block)
end

#headersObject



30
31
32
# File 'lib/gh/pagination.rb', line 30

def headers
  @page.headers
end

#inspectObject



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

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

#to_aryObject



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

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