class GearedPagination::PortionAtCursor::Selection

Attributes

orders[R]
scope[R]

Public Class Methods

new(scope, orders) click to toggle source
# File lib/geared_pagination/portions/portion_at_cursor.rb, line 52
def initialize(scope, orders)
  @scope, @orders = scope, orders
end

Public Instance Methods

from(cursor) click to toggle source
# File lib/geared_pagination/portions/portion_at_cursor.rb, line 56
def from(cursor)
  if condition = condition_on(cursor)
    scope.where(condition)
  else
    scope.all
  end
end

Private Instance Methods

condition_on(cursor) click to toggle source
# File lib/geared_pagination/portions/portion_at_cursor.rb, line 67
def condition_on(cursor)
  conditions_on(cursor).reduce { |left, right| left.or(right) }
end
conditions_on(cursor) click to toggle source
# File lib/geared_pagination/portions/portion_at_cursor.rb, line 71
def conditions_on(cursor)
  if orders.all? { |order| cursor.include?(order.attribute) }
    matches.collect { |match| match.condition_on(table, cursor) }
  else
    []
  end
end
matches() click to toggle source
# File lib/geared_pagination/portions/portion_at_cursor.rb, line 79
def matches
  orders.size.downto(1).collect { |i| Match.new(orders[i - 1], orders.take(i - 1)) }
end