Class: Queryko::Filters::Paginate
- Defined in:
- lib/queryko/filters/paginate.rb
Instance Attribute Summary collapse
-
#default_limit ⇒ Object
readonly
Returns the value of attribute default_limit.
-
#lower_limit ⇒ Object
readonly
Returns the value of attribute lower_limit.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#upper_limit ⇒ Object
readonly
Returns the value of attribute upper_limit.
Attributes inherited from Base
#as, #column_name, #feature, #field, #query_object, #table_name, #table_name_override
Instance Method Summary collapse
- #get_limit ⇒ Object
-
#initialize(options = {}, feature) ⇒ Paginate
constructor
A new instance of Paginate.
- #limit ⇒ Object
- #page ⇒ Object
- #param_key_format ⇒ Object
- #perform(collection, paginate, query_object) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}, feature) ⇒ Paginate
Returns a new instance of Paginate.
6 7 8 9 10 11 |
# File 'lib/queryko/filters/paginate.rb', line 6 def initialize( = {}, feature) @upper_limit = .fetch(:upper) { 100 } @lower_limit = .fetch(:lower) { 10 } super(, feature) end |
Instance Attribute Details
#default_limit ⇒ Object (readonly)
Returns the value of attribute default_limit.
4 5 6 |
# File 'lib/queryko/filters/paginate.rb', line 4 def default_limit @default_limit end |
#lower_limit ⇒ Object (readonly)
Returns the value of attribute lower_limit.
4 5 6 |
# File 'lib/queryko/filters/paginate.rb', line 4 def lower_limit @lower_limit end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/queryko/filters/paginate.rb', line 4 def params @params end |
#upper_limit ⇒ Object (readonly)
Returns the value of attribute upper_limit.
4 5 6 |
# File 'lib/queryko/filters/paginate.rb', line 4 def upper_limit @upper_limit end |
Instance Method Details
#get_limit ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# 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 ⇒ Object
31 32 33 |
# File 'lib/queryko/filters/paginate.rb', line 31 def limit get_limit end |
#page ⇒ Object
27 28 29 |
# File 'lib/queryko/filters/paginate.rb', line 27 def page params[:page] || 1 end |
#param_key_format ⇒ Object
46 47 48 |
# File 'lib/queryko/filters/paginate.rb', line 46 def param_key_format "paginate" end |
#perform(collection, paginate, query_object) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |