Sha256: c99b2fffe60ca4562825b94535bea846df90a7c77ed4cd779235ba48617b4827

Contents?: true

Size: 810 Bytes

Versions: 22

Compression:

Stored size: 810 Bytes

Contents

# See the Pagy documentation: https://ddnexus.github.io/pagy/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]  ||= params[vars[:page_param] || DEFAULT[:page_param]]
      vars
    end
  end
  Backend.prepend ArrayExtra
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
pagy-6.0.0 lib/pagy/extras/array.rb
pagy-5.10.1 lib/pagy/extras/array.rb
pagy-5.10.0 lib/pagy/extras/array.rb
pagy-5.9.3 lib/pagy/extras/array.rb
pagy-5.9.2 lib/pagy/extras/array.rb
pagy-5.9.1 lib/pagy/extras/array.rb
pagy-5.9.0 lib/pagy/extras/array.rb
pagy-5.8.1 lib/pagy/extras/array.rb
pagy-5.8.0 lib/pagy/extras/array.rb
pagy-5.7.6 lib/pagy/extras/array.rb
pagy-5.7.5 lib/pagy/extras/array.rb
pagy-5.7.4 lib/pagy/extras/array.rb
pagy-5.7.3 lib/pagy/extras/array.rb
pagy-5.7.2 lib/pagy/extras/array.rb
pagy-5.7.1 lib/pagy/extras/array.rb
pagy-5.7.0 lib/pagy/extras/array.rb
pagy-5.6.10 lib/pagy/extras/array.rb
pagy-5.6.9 lib/pagy/extras/array.rb
pagy-5.6.8 lib/pagy/extras/array.rb
pagy-5.6.7 lib/pagy/extras/array.rb