Class: Argus::Trail::Pagination::SimplePage
- Inherits:
-
Object
- Object
- Argus::Trail::Pagination::SimplePage
- Includes:
- Enumerable
- Defined in:
- lib/argus/trail/pagination.rb
Overview
Minimal stand-in for a Kaminari page, used only when the host app hasn't bundled Kaminari. Implements just enough of Kaminari's relation interface for the engine's views (current_page, total_pages, total_count, each).
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
- #any? ⇒ Boolean
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(relation, page:, per:) ⇒ SimplePage
constructor
A new instance of SimplePage.
- #size ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(relation, page:, per:) ⇒ SimplePage
Returns a new instance of SimplePage.
12 13 14 15 16 17 |
# File 'lib/argus/trail/pagination.rb', line 12 def initialize(relation, page:, per:) @current_page = [ page.to_i, 1 ].max @per_page = per @total_count = relation.count @records = relation.offset((@current_page - 1) * per).limit(per).to_a end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
10 11 12 |
# File 'lib/argus/trail/pagination.rb', line 10 def current_page @current_page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
10 11 12 |
# File 'lib/argus/trail/pagination.rb', line 10 def per_page @per_page end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
10 11 12 |
# File 'lib/argus/trail/pagination.rb', line 10 def total_count @total_count end |
Instance Method Details
#any? ⇒ Boolean
20 |
# File 'lib/argus/trail/pagination.rb', line 20 def any? = @records.any? |
#each(&block) ⇒ Object
19 |
# File 'lib/argus/trail/pagination.rb', line 19 def each(&block) = @records.each(&block) |
#empty? ⇒ Boolean
21 |
# File 'lib/argus/trail/pagination.rb', line 21 def empty? = @records.empty? |
#size ⇒ Object
22 |
# File 'lib/argus/trail/pagination.rb', line 22 def size = @records.size |
#total_pages ⇒ Object
24 25 26 27 |
# File 'lib/argus/trail/pagination.rb', line 24 def total_pages return 0 if per_page.zero? (total_count.to_f / per_page).ceil end |