class Queryko::Filters::Paginate

Attributes

default_limit[R]
lower_limit[R]
params[R]
upper_limit[R]

Public Class Methods

new(options = {}, feature) click to toggle source
Calls superclass method Queryko::Filters::Base::new
# File lib/queryko/filters/paginate.rb, line 6
def initialize(options = {}, feature)
  @upper_limit = options.fetch(:upper) { 100 }
  @lower_limit = options.fetch(:lower) { 10 }

  super(options, feature)
end

Public Instance Methods

get_limit() click to toggle source
# File lib/queryko/filters/paginate.rb, line 35
def get_limit
   lim = params[:limit].to_i
   if lower_limit > lim
     lower_limit
   elsif lim > upper_limit
     upper_limit
   else
     lim
   end
end
limit() click to toggle source
# File lib/queryko/filters/paginate.rb, line 31
def limit
  get_limit
end
page() click to toggle source
# File lib/queryko/filters/paginate.rb, line 27
def page
  params[:page] || 1
end
param_key_format() click to toggle source
# File lib/queryko/filters/paginate.rb, line 46
def param_key_format
  "paginate"
end
perform(collection, paginate, query_object) click to toggle source
# File lib/queryko/filters/paginate.rb, line 13
def perform(collection, paginate, query_object)
  if paginate
    @params = query_object.params

    if defined?(WillPaginate)
      collection.paginate(page: page, per_page: limit)
    elsif defined?(Kaminari)
      collection.page(page).per(limit)
    else
      raise 'Only kaminari and wil_paginate are supported'
    end
  end
end