Sha256: b79ec5dfd720d602d188e84aec865ac92ed8b5bacecce45fe3f110a40970eb8f

Contents?: true

Size: 1.19 KB

Versions: 27

Compression:

Stored size: 1.19 KB

Contents

# See Pagy::Countless API documentation: https://ddnexus.github.io/pagy/docs/api/countless
# frozen_string_literal: true

require 'pagy'

class Pagy
  # No need to know the count to paginate
  class Countless < Pagy
    # Merge and validate the options, do some simple arithmetic and set a few instance variables
    def initialize(vars = {}) # rubocop:disable Lint/MissingSuper
      normalize_vars(vars)
      setup_vars(page: 1, outset: 0)
      setup_items_var
      setup_offset_var
      setup_params_var
    end

    # Finalize the instance variables based on the fetched size
    def finalize(fetched_size)
      raise OverflowError.new(self, :page, "to be < #{@page}", @page) if fetched_size.zero? && @page > 1

      @pages = @last = (fetched_size > @items ? @page + 1 : @page)
      @in    = [fetched_size, @items].min
      @from  = @in.zero? ? 0 : @offset - @outset + 1
      @to    = @offset - @outset + @in
      @prev  = (@page - 1 unless @page == 1)
      @next  = @page == @last ? (1 if @vars[:cycle]) : @page + 1
      self
    end

    # Override the original series.
    # Return nil if :countless_minimal is enabled
    def series(*, **)
      super unless @vars[:countless_minimal]
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
pagy-8.0.1 gem/lib/pagy/countless.rb
pagy-8.0.0 lib/pagy/countless.rb
pagy-7.0.11 lib/pagy/countless.rb
pagy-7.0.10 lib/pagy/countless.rb
pagy-7.0.9 lib/pagy/countless.rb
pagy-7.0.8 lib/pagy/countless.rb
pagy-7.0.7 lib/pagy/countless.rb
pagy-7.0.6 lib/pagy/countless.rb
pagy-7.0.5 lib/pagy/countless.rb
pagy-7.0.4 lib/pagy/countless.rb
pagy-7.0.3 lib/pagy/countless.rb
pagy-7.0.2 lib/pagy/countless.rb
pagy-7.0.1 lib/pagy/countless.rb
pagy-6.5.0 lib/pagy/countless.rb
pagy-7.0.0 lib/pagy/countless.rb
pagy-6.4.4 lib/pagy/countless.rb
pagy-6.4.3 lib/pagy/countless.rb
pagy-6.4.2 lib/pagy/countless.rb
pagy-6.4.1 lib/pagy/countless.rb
pagy-6.4.0 lib/pagy/countless.rb