Sha256: 993bffef037b2cd8df1ececb1960bd7b06a666882ff6a75c9f691b86deefe77c
Contents?: true
Size: 881 Bytes
Versions: 16
Compression:
Stored size: 881 Bytes
Contents
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/arel # frozen_string_literal: true class Pagy module Backend private def pagy_arel(collection, vars={}) pagy = Pagy.new(pagy_arel_get_vars(collection, vars)) [ pagy, pagy_get_items(collection, pagy) ] end def pagy_arel_get_vars(collection, vars) pagy_set_items_from_params(vars) if defined?(UseItemsExtra) vars[:count] ||= pagy_arel_count(collection) vars[:page] ||= params[ vars[:page_param] || VARS[:page_param] ] vars end def pagy_arel_count(collection) if collection.group_values.empty? # COUNT(*) collection.count(:all) else # COUNT(*) OVER () sql = Arel.star.count.over(Arel::Nodes::Grouping.new([])) collection.unscope(:order).limit(1).pluck(sql).first.to_i end end end end
Version data entries
16 entries across 16 versions & 2 rubygems