module Folio::WillPaginate::ActiveRecord::Pagination
Public Instance Methods
build_page()
click to toggle source
set up the proxy to receive the calls
# File lib/folio/will_paginate/active_record.rb, line 95 def build_page PageProxy.new(self) end
default_per_page()
click to toggle source
don't try and look at Class (ActiveRecord::Base.class, etc.) for defaults
# File lib/folio/will_paginate/active_record.rb, line 111 def default_per_page Folio.per_page end
fill_page(proxy)
click to toggle source
pull the result out of the proxy
# File lib/folio/will_paginate/active_record.rb, line 100 def fill_page(proxy) proxy.result end
page(num)
click to toggle source
make sure the relation coming out of page(…) is folio-compatible
Calls superclass method
# File lib/folio/will_paginate/active_record.rb, line 105 def page(num) super.extending(RelationMethods) end
paginate(options={})
click to toggle source
Calls superclass method
# File lib/folio/will_paginate/active_record.rb, line 117 def paginate(options={}) if !options.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' options[:total_entries] = except(:group, :select).select(group_values).uniq.count else options[:total_entries] = except(:group, :select).select(group_values).distinct.count end else options[:total_entries] = unscoped.from("(#{to_sql}) a").count end end end super(options).to_a end