class Zaikio::Client::Helpers::Pagination::Relation
Public Instance Methods
clone()
click to toggle source
Calls superclass method
# File lib/zaikio/client/helpers/pagination.rb, line 104 def clone # We use cloning when fetching a second page using the same scope/query, however # we want to clear any loaded records from @find_some before doing so. super.tap { |obj| obj.instance_variable_set(:@find_some, nil) } end
each(&block)
click to toggle source
Unlike the default implementation in Spyke
, this version of each
is recursive and will repeatedly paginate through the remote API until it runs out of records.
To avoid this behaviour, you can ask for a Lazy enumerator to take just the records you need, e.g.:
User.all.lazy.take(3).to_a #=> [.., .., ..]
# File lib/zaikio/client/helpers/pagination.rb, line 94 def each(&block) return to_enum(:each) unless block_given? find_some.each(&block) return if !supports_pagination? || last_page? puts "There are #{total_pages} pages, I will load more pages automatically" if first_page? clone.page(next_page).each(&block) end
first_page?()
click to toggle source
# File lib/zaikio/client/helpers/pagination.rb, line 70 def first_page? current_page == 1 end
last_page?()
click to toggle source
# File lib/zaikio/client/helpers/pagination.rb, line 78 def last_page? current_page >= total_pages end
next_page()
click to toggle source
# File lib/zaikio/client/helpers/pagination.rb, line 74 def next_page current_page + 1 end
supports_pagination?()
click to toggle source
# File lib/zaikio/client/helpers/pagination.rb, line 82 def supports_pagination? current_page.present? end