Module: Deli::Pagination::Collection
- Defined in:
- lib/deli/pagination.rb
Instance Method Summary collapse
-
#count ⇒ Object
:nodoc:.
- #current_page ⇒ Object
- #end_count ⇒ Object
- #first_page ⇒ Object
- #has_next? ⇒ Boolean
- #has_prev? ⇒ Boolean
- #last_page ⇒ Object
- #next_page ⇒ Object
- #page_count ⇒ Object
- #page_size ⇒ Object
- #prev_page ⇒ Object
- #start_count ⇒ Object
-
#total_count ⇒ Object
:nodoc:.
Instance Method Details
#count ⇒ Object
:nodoc:
99 100 101 |
# File 'lib/deli/pagination.rb', line 99 def count #:nodoc: limit_value ? length : super end |
#current_page ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/deli/pagination.rb', line 52 def current_page unless @current_page if offset_value.blank? || offset_value.zero? @current_page = 1 else @current_page = (offset_value.to_f / limit_value).to_i + 1 end end @current_page end |
#end_count ⇒ Object
48 49 50 |
# File 'lib/deli/pagination.rb', line 48 def end_count @end_count ||= start_count + size end |
#first_page ⇒ Object
80 81 82 |
# File 'lib/deli/pagination.rb', line 80 def first_page 1 end |
#has_next? ⇒ Boolean
36 37 38 |
# File 'lib/deli/pagination.rb', line 36 def has_next? last_page > current_page end |
#has_prev? ⇒ Boolean
40 41 42 |
# File 'lib/deli/pagination.rb', line 40 def has_prev? current_page > first_page end |
#last_page ⇒ Object
84 85 86 |
# File 'lib/deli/pagination.rb', line 84 def last_page page_count end |
#next_page ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/deli/pagination.rb', line 64 def next_page unless @next_page @next_page = current_page + 1 > last_page ? last_page : current_page + 1 end @next_page end |
#page_count ⇒ Object
92 93 94 |
# File 'lib/deli/pagination.rb', line 92 def page_count @page_count ||= (total_count.to_f / page_size).ceil end |
#page_size ⇒ Object
88 89 90 |
# File 'lib/deli/pagination.rb', line 88 def page_size @page_size ||= limit_value end |
#prev_page ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/deli/pagination.rb', line 72 def prev_page unless @prev_page @prev_page = current_page - 1 < first_page ? first_page : current_page - 1 end @prev_page end |
#start_count ⇒ Object
44 45 46 |
# File 'lib/deli/pagination.rb', line 44 def start_count @start_count ||= (((current_page || 1) - 1) * page_size) end |
#total_count ⇒ Object
:nodoc:
104 105 106 |
# File 'lib/deli/pagination.rb', line 104 def total_count @total_count ||= proxy_scope.count(.except(:limit, :offset, :order)) end |