BigW Consortium Gitlab

collection.rb 562 Bytes
Newer Older
1 2
module Github
  class Collection
3 4 5 6 7 8
    attr_reader :options

    def initialize(options)
      @options = options
    end

9 10
    def fetch(url, query = {})
      return [] if url.blank?
11 12 13

      Enumerator.new do |yielder|
        loop do
14
          response = client.get(url, query)
15
          response.body.each { |item| yielder << item }
16

17
          raise StopIteration unless response.rels.key?(:next)
18
          url = response.rels[:next]
19 20 21 22 23 24 25
        end
      end.lazy
    end

    private

    def client
26
      @client ||= Github::Client.new(options)
27 28 29
    end
  end
end