Sha256: c22fdbc57a0bd02ad27a4e0dc73cd9d2667c4396c8de775a7741da74fd1d2eea
Contents?: true
Size: 829 Bytes
Versions: 2
Compression:
Stored size: 829 Bytes
Contents
# See the Pagy documentation: https://ddnexus.github.io/pagy/extras/arel # encoding: utf-8 # frozen_string_literal: true class Pagy module Backend ; private def pagy_arel(collection, vars={}) pagy = Pagy.new(pagy_arel_get_vars(collection, vars)) return pagy, pagy_get_items(collection, pagy) end def pagy_arel_get_vars(collection, vars) 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 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pagy-3.7.0 | lib/pagy/extras/arel.rb |
pagy-3.6.0 | lib/pagy/extras/arel.rb |