module PDC::Resource::Pagination

Public Instance Methods

each_page() { |relation| ... } click to toggle source
# File lib/pdc/resource/relation/pagination.rb, line 18
def each_page
  return to_enum(:each_page) unless block_given?

  # results are not fetched yet so use the clone for next pages
  # and create new relation based on the next_page metadata

  relation = clone
  yield relation

  until (next_page = relation.next_page).nil?
    relation = self.class.new(klass, uri: next_page)
    yield relation
  end
end