module Pageable::ActiveRecord::Relation

Public Instance Methods

current_page() click to toggle source
# File lib/pageable/active_record/relation.rb, line 30
def current_page
  @current_page ||= (offset_value.to_f / fixed_limit_value).ceil + 1
end
first_page() click to toggle source
# File lib/pageable/active_record/relation.rb, line 42
def first_page
  1
end
last_page() click to toggle source
# File lib/pageable/active_record/relation.rb, line 46
def last_page
  total_pages
end
next_page() click to toggle source
# File lib/pageable/active_record/relation.rb, line 38
def next_page
  @next_page ||= current_page < total_pages ? (current_page + 1) : nil
end
out_of_bounds?() click to toggle source
# File lib/pageable/active_record/relation.rb, line 50
def out_of_bounds?
  @out_of_bounds ||= current_page > total_pages or current_page < first_page
end
padding(value) click to toggle source
# File lib/pageable/active_record/relation.rb, line 11
def padding(value)
  @padding = value
  r = (offset_value + value) < 0 ? self : offset(offset_value + value)
  decrease_limit? ? r.limit(limit_value + value) : r
end
per(value) click to toggle source
# File lib/pageable/active_record/relation.rb, line 6
def per(value)
  value = [value.to_i, 1].max
  limit(value).offset(value * (offset_value / limit_value))
end
previous_page() click to toggle source
# File lib/pageable/active_record/relation.rb, line 34
def previous_page
  @previous_page ||= current_page > 1 ? (current_page - 1) : nil
end
total_count() click to toggle source
# File lib/pageable/active_record/relation.rb, line 17
def total_count
  @total_count ||= begin
    r = except(:offset, :limit, :order, :reorder)
    r = r.except(:includes) unless eager_loading?
    r = r.count
    r.respond_to?(:count) ? r.count : r
  end
end
total_pages() click to toggle source
# File lib/pageable/active_record/relation.rb, line 26
def total_pages
  @total_pages ||= [(fixed_total_count.to_f / fixed_limit_value).ceil, 1].max
end

Protected Instance Methods

decrease_limit?() click to toggle source
# File lib/pageable/active_record/relation.rb, line 64
def decrease_limit?
  padding_negative? and offset_value == 0
end
fixed_limit_value() click to toggle source
# File lib/pageable/active_record/relation.rb, line 72
def fixed_limit_value
  limit_value - (decrease_limit? ? @padding : 0)
end
fixed_total_count() click to toggle source
# File lib/pageable/active_record/relation.rb, line 68
def fixed_total_count
  total_count - (padding_negative? ? @padding : 0)
end
has_padding?() click to toggle source
# File lib/pageable/active_record/relation.rb, line 56
def has_padding?
  !defined?(@padding).nil?
end
padding_negative?() click to toggle source
# File lib/pageable/active_record/relation.rb, line 60
def padding_negative?
  has_padding? and @padding < 0
end