Module: Kaminari::PaginatableWithoutCount
- Defined in:
- lib/kaminari/activerecord/active_record_relation_methods.rb,
lib/kaminari/activerecord/active_record_relation_methods.rb
Overview
A module that makes AR::Relation paginatable without having to cast another SELECT COUNT query
Defined Under Namespace
Modules: LimitValueSetter
Instance Method Summary collapse
-
#last_page? ⇒ Boolean
The page wouldn’t be the last page if there’s “limit + 1” record.
-
#load ⇒ Object
Overwrite AR::Relation#load to actually load one more record to judge if the page has next page then store the result in @_has_next ivar.
-
#out_of_range? ⇒ Boolean
Empty relation needs no pagination.
-
#total_count ⇒ Object
Force to raise an exception if #total_count is called explicitly.
Instance Method Details
#last_page? ⇒ Boolean
The page wouldn’t be the last page if there’s “limit + 1” record
109 110 111 |
# File 'lib/kaminari/activerecord/active_record_relation_methods.rb', line 109 def last_page? !out_of_range? && !@_has_next end |
#load ⇒ Object
Overwrite AR::Relation#load to actually load one more record to judge if the page has next page then store the result in @_has_next ivar
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/kaminari/activerecord/active_record_relation_methods.rb', line 90 def load if loaded? || limit_value.nil? super else set_limit_value limit_value + 1 super set_limit_value limit_value - 1 if @records.any? @records = @records.dup if (frozen = @records.frozen?) @_has_next = !!@records.delete_at(limit_value) @records.freeze if frozen end self end end |
#out_of_range? ⇒ Boolean
Empty relation needs no pagination
114 115 116 117 |
# File 'lib/kaminari/activerecord/active_record_relation_methods.rb', line 114 def out_of_range? load unless loaded? @records.empty? end |
#total_count ⇒ Object
Force to raise an exception if #total_count is called explicitly.
120 121 122 123 |
# File 'lib/kaminari/activerecord/active_record_relation_methods.rb', line 120 def total_count raise "This scope is marked as a non-count paginable scope and can't be used in combination " \ "with `#paginate' or `#page_entries_info'. Use #link_to_next_page or #link_to_previous_page instead." end |