Class: Hubkit::Paginator Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hubkit/paginator.rb

Overview

This class is abstract.

A class which implements an Enumerable which yields each resource returned

by GitHub in turn, and handles the pagination for you (acts like a flat array, not an array of pages)

Direct Known Subclasses

EventPaginator, IssuePaginator, RepoPaginator

Instance Method Summary collapse

Constructor Details

#initialize {|result| ... } ⇒ Paginator

Construct a new paginator

Yield Parameters:

  • result (Object)

    each page of results


10
11
12
# File 'lib/hubkit/paginator.rb', line 10

def initialize(&block)
  @block = block
end

Instance Method Details

#each {|result| ... } ⇒ Object

Iterate through each page of the results and perform a block

Yield Parameters:

  • result (Object)

    each page of the


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hubkit/paginator.rb', line 16

def each
  i = 1
  loop do
    results = @block.call i
    results.each do |result|
      yield result
    end
    i += 1
    break if results.length == 0
  end
end