Sha256: 9c192596c2384baa1cb2761ac8b9219729de9ed3c4ce9bd6352eca317ac5384c

Contents?: true

Size: 785 Bytes

Versions: 15

Compression:

Stored size: 785 Bytes

Contents

# See the Pagy documentation: https://ddnexus.github.io/pagy/docs/extras/array
# frozen_string_literal: true

class Pagy # :nodoc:
  # Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
  module ArrayExtra
    private

    # Return Pagy object and paginated items
    def pagy_array(array, vars = {})
      pagy = Pagy.new(pagy_array_get_vars(array, vars))
      [pagy, array[pagy.offset, pagy.items]]
    end

    # Sub-method called only by #pagy_array: here for easy customization of variables by overriding
    def pagy_array_get_vars(array, vars)
      pagy_set_items_from_params(vars) if defined?(ItemsExtra)
      vars[:count] ||= array.size
      vars[:page]  ||= pagy_get_page(vars)
      vars
    end
  end
  Backend.prepend ArrayExtra
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pagy-8.6.3 lib/pagy/extras/array.rb
pagy-8.6.2 lib/pagy/extras/array.rb
pagy-8.6.1 lib/pagy/extras/array.rb
pagy-8.6.0 lib/pagy/extras/array.rb
pagy-8.5.0 lib/pagy/extras/array.rb
pagy-8.4.5 lib/pagy/extras/array.rb
pagy-8.4.4 lib/pagy/extras/array.rb
pagy-8.4.3 lib/pagy/extras/array.rb
pagy-8.4.2 lib/pagy/extras/array.rb
pagy-8.4.1 lib/pagy/extras/array.rb
pagy-8.4.0 lib/pagy/extras/array.rb
pagy-8.3.0 lib/pagy/extras/array.rb
pagy-8.2.2 lib/pagy/extras/array.rb
pagy-8.2.1 lib/pagy/extras/array.rb
pagy-8.2.0 lib/pagy/extras/array.rb