Module: Folio::WillPaginate::ActiveRecord::Pagination
- Includes:
- Ordinal
- Defined in:
- lib/folio/will_paginate/active_record.rb
Defined Under Namespace
Classes: PageProxy
Constant Summary
Constants included from Folio
Instance Method Summary collapse
-
#build_page ⇒ Object
set up the proxy to receive the calls.
-
#default_per_page ⇒ Object
don’t try and look at Class (ActiveRecord::Base.class, etc.) for defaults.
-
#fill_page(proxy) ⇒ Object
pull the result out of the proxy.
-
#page(num) ⇒ Object
make sure the relation coming out of page(…) is folio-compatible.
- #paginate(options = {}) ⇒ Object
Methods included from Ordinal
Methods included from Folio
Methods included from PerPageIncluder
Methods included from PerPage
Instance Method Details
#build_page ⇒ Object
set up the proxy to receive the calls
95 96 97 |
# File 'lib/folio/will_paginate/active_record.rb', line 95 def build_page PageProxy.new(self) end |
#default_per_page ⇒ Object
don’t try and look at Class (ActiveRecord::Base.class, etc.) for defaults
111 112 113 |
# File 'lib/folio/will_paginate/active_record.rb', line 111 def default_per_page Folio.per_page end |
#fill_page(proxy) ⇒ Object
pull the result out of the proxy
100 101 102 |
# File 'lib/folio/will_paginate/active_record.rb', line 100 def fill_page(proxy) proxy.result end |
#page(num) ⇒ Object
make sure the relation coming out of page(…) is folio-compatible
105 106 107 |
# File 'lib/folio/will_paginate/active_record.rb', line 105 def page(num) super.extending(RelationMethods) end |
#paginate(options = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/folio/will_paginate/active_record.rb', line 117 def paginate(={}) if !.has_key?(:total_entries) scope = if ::Rails.version < '4' self.scoped elsif self.is_a?(::ActiveRecord::Relation) self elsif self < ::ActiveRecord::Base self.all else self.scope end group_values = scope.group_values unless group_values.empty? # total_entries left to an auto-count, but the relation being # paginated has a grouping. we need to do a special count, lest # self.count give us a hash instead of the integer we expect. having_clause_empty = Rails.version < '5' ? scope.having_values.empty? : scope.having_clause.empty? if having_clause_empty && group_values.length == 1 # multi-column distinct counts are broken right now (as of rails 4.2.5) :( if Rails.version < '5' [:total_entries] = except(:group, :select).select(group_values).uniq.count else [:total_entries] = except(:group, :select).select(group_values).distinct.count end else [:total_entries] = unscoped.from("(#{to_sql}) a").count end end end super().to_a end |