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

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/pagy-4.11.0/lib/pagy/extras/arel.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/pagy-4.11.0/lib/pagy/extras/arel.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/pagy-4.11.0/lib/pagy/extras/arel.rb
pagy-4.11.0 lib/pagy/extras/arel.rb
pagy-4.10.2 lib/pagy/extras/arel.rb
pagy-4.10.1 lib/pagy/extras/arel.rb
pagy-4.10.0 lib/pagy/extras/arel.rb
pagy-4.9.0 lib/pagy/extras/arel.rb
pagy-4.8.1 lib/pagy/extras/arel.rb
pagy-4.8.0 lib/pagy/extras/arel.rb
pagy-4.7.1 lib/pagy/extras/arel.rb
pagy-4.7.0 lib/pagy/extras/arel.rb
pagy-4.6.0 lib/pagy/extras/arel.rb
pagy-4.5.1 lib/pagy/extras/arel.rb
pagy-4.5.0 lib/pagy/extras/arel.rb
pagy-4.4.0 lib/pagy/extras/arel.rb