Closed vizvamitra closed 7 years ago
@dmitry-mukhin I've tried to make the inmplementation more understandable. What do you think about it?
def each
return enum_for(:each) unless block_given?
resource_enumerator.each { |object| yield object }
self
end
private
def get_next_page
return nil if fully_loaded?
next_page = build_data(api.get(@data.meta['next']))
@data = OpenStruct.new(
meta: next_page.meta,
objects: objects + next_page.objects
)
next_page
end
def resource_enumerator
Enumerator.new do |yielder|
objects.each { |obj| yielder << obj }
while next_page = get_next_page do
next_page.objects.each { |obj| yielder << obj }
end
end
end
This change will break gem's interface, so we should 🎉bump the major version🎉 later. Also I think that this change needs an upgrade notes section which I'll introduce later on in a separate PR.