Refactoring collection wrapper

parent 2c92cc52
module Github module Github
class Collection class Collection
def initialize(url) def fetch(url, query = {})
@url = url return [] if url.blank?
end
def fetch(query = {})
return [] if @url.blank?
Enumerator.new do |yielder| Enumerator.new do |yielder|
loop do loop do
response = client.get(@url, query) response = client.get(url, query)
response.body.each { |item| yielder << item } response.body.each { |item| yielder << item }
raise StopIteration unless response.rels.key?(:next) raise StopIteration unless response.rels.key?(:next)
@url = response.rels[:next] url = response.rels[:next]
end end
end.lazy end.lazy
end end
......
...@@ -5,7 +5,7 @@ module Github ...@@ -5,7 +5,7 @@ module Github
end end
def fetch def fetch
Collection.new(repos_url).fetch Collection.new.fetch(repos_url)
end end
private private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment