Module: KaminariExtension::QueryExt
- Extended by:
- ActiveSupport::Concern
- Includes:
- Kaminari::PageScopeMethods
- Defined in:
- lib/kaminari_extension.rb
Instance Method Summary collapse
- #limit_value ⇒ Object
- #max_per_page ⇒ Object
- #offset_value ⇒ Object
- #page(num) ⇒ Object
- #per(num) ⇒ Object
- #total_count ⇒ Object
Instance Method Details
#limit_value ⇒ Object
22 23 24 |
# File 'lib/kaminari_extension.rb', line 22 def limit_value criteria[:limit] end |
#max_per_page ⇒ Object
34 35 36 |
# File 'lib/kaminari_extension.rb', line 34 def max_per_page @klass.max_per_page end |
#offset_value ⇒ Object
26 27 28 |
# File 'lib/kaminari_extension.rb', line 26 def offset_value criteria[:skip] end |
#page(num) ⇒ Object
38 39 40 41 |
# File 'lib/kaminari_extension.rb', line 38 def page(num) limit(@klass.default_per_page).skip(@klass.default_per_page * ([num.to_i, 1].max - 1)) self end |
#per(num) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kaminari_extension.rb', line 43 def per(num) if (n = num.to_i) <= 0 self elsif max_per_page && max_per_page < n new_offset_value = offset_value / limit_value * max_per_page limit(max_per_page).offset(new_offset_value) else new_offset_value = offset_value / limit_value * n limit(n).offset(new_offset_value) end self end |
#total_count ⇒ Object
30 31 32 |
# File 'lib/kaminari_extension.rb', line 30 def total_count count end |