Module: PDC::Resource::Pagination

Extended by:
ActiveSupport::Concern
Included in:
Relation
Defined in:
lib/pdc/resource/relation/pagination.rb

Instance Method Summary collapse

Instance Method Details

#each_page {|relation| ... } ⇒ Object

Yields:

  • (relation)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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