module OrderQuery

This gem finds the next or previous record(s) relative to the current one efficiently using keyset pagination, e.g. for navigation or infinite scroll.

Constants

VERSION

Attributes

wrap_top_level_or[RW]

Public Instance Methods

seek(*spec) click to toggle source

@param [ActiveRecord::Relation] scope optional first argument

(default: self.class.all)

@param [Array<Array<Symbol,String>>, OrderQuery::Spec] order_spec @return [OrderQuery::Point] @example

users = User.active
user  = users.find(42)
next_user = user.seek(users, [:activated_at, :desc], [:id, :desc]).next
# File lib/order_query.rb, line 21
def seek(*spec)
  fst = spec.first
  if fst.nil? || fst.is_a?(ActiveRecord::Relation) ||
     fst.is_a?(ActiveRecord::Base)
    scope = spec.shift
  end
  scope ||= self.class.all
  scope.seek(*spec).at(self)
end