Module: AppQuery::Paginatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app_query/paginatable.rb
Overview
Adds pagination support to query classes.
Provides two modes:
- With count: Full pagination with page numbers (uses COUNT query)
- Without count: Simple prev/next for large datasets (uses limit+1 trick)
Compatible with Kaminari view helpers.
Defined Under Namespace
Classes: PaginatedResult
Instance Method Summary collapse
- #entries ⇒ Object
- #paginate(page: 1, per_page: self.class.per_page, without_count: false) ⇒ Object
- #total_count ⇒ Object
- #unpaginated_query ⇒ Object
Instance Method Details
#entries ⇒ Object
115 116 117 |
# File 'lib/app_query/paginatable.rb', line 115 def entries @_entries ||= build_paginated_result(super) end |
#paginate(page: 1, per_page: self.class.per_page, without_count: false) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/app_query/paginatable.rb', line 108 def paginate(page: 1, per_page: self.class.per_page, without_count: false) @page = page @per_page = per_page @without_count = without_count self end |
#total_count ⇒ Object
119 120 121 |
# File 'lib/app_query/paginatable.rb', line 119 def total_count @_total_count ||= unpaginated_query.count end |
#unpaginated_query ⇒ Object
123 124 125 126 127 |
# File 'lib/app_query/paginatable.rb', line 123 def unpaginated_query base_query .render(**render_vars.except(:page, :per_page)) .with_binds(**bind_vars) end |