Module: AppQuery::Paginatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app_query/paginatable.rb
Overview
Note:
Middleware concern that adds pagination support to BaseQuery subclasses.
Include this module in your query class to enable pagination with Kaminari-compatible result objects.
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)
Defined Under Namespace
Classes: PaginatedResult
Instance Method Summary collapse
-
#entries ⇒ PaginatedResult, Array<Hash>
Executes the query and returns paginated results.
-
#paginate(page: 1, per_page: self.class.per_page, without_count: false) ⇒ self
Enables pagination for this query.
-
#total_count ⇒ Integer
Returns the total count of records (without pagination).
-
#unpaginated ⇒ self
Disables pagination, returning all results.
Instance Method Details
#entries ⇒ PaginatedResult, Array<Hash>
Executes the query and returns paginated results.
201 202 203 |
# File 'lib/app_query/paginatable.rb', line 201 def entries @_entries ||= build_paginated_result(super) end |
#paginate(page: 1, per_page: self.class.per_page, without_count: false) ⇒ self
Enables pagination for this query.
178 179 180 181 182 183 |
# File 'lib/app_query/paginatable.rb', line 178 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 ⇒ Integer
Returns the total count of records (without pagination).
Executes a separate COUNT query. Result is memoized.
210 211 212 |
# File 'lib/app_query/paginatable.rb', line 210 def total_count @_total_count ||= unpaginated_query.count end |
#unpaginated ⇒ self
Disables pagination, returning all results.
191 192 193 194 195 |
# File 'lib/app_query/paginatable.rb', line 191 def unpaginated @page = nil @per_page = nil self end |