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 ⇒ 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
128 129 130 |
# File 'lib/app_query/paginatable.rb', line 128 def entries @_entries ||= build_paginated_result(super) end |
#paginate(page: 1, per_page: self.class.per_page, without_count: false) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/app_query/paginatable.rb', line 121 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
132 133 134 |
# File 'lib/app_query/paginatable.rb', line 132 def total_count @_total_count ||= unpaginated_query.count end |
#unpaginated_query ⇒ Object
136 137 138 139 140 |
# File 'lib/app_query/paginatable.rb', line 136 def unpaginated_query base_query .render(**render_vars.except(:page, :per_page)) .with_binds(**bind_vars) end |