Sha256: 653f1843040c7f4f1a051e5604e6853a3627c60403028a52517820f7d2926644

Contents?: true

Size: 1.24 KB

Versions: 19

Compression:

Stored size: 1.24 KB

Contents

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

class Pagy # :nodoc:
  # 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
      assign_vars(DEFAULT, vars)
      assign_and_check(page: 1, outset: 0)
      assign_limit
      assign_offset
    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

      @last = fetched_size > @limit ? @page + 1 : @page
      @last = @vars[:max_pages] if @vars[:max_pages] && @last > @vars[:max_pages]
      check_overflow
      @in   = [fetched_size, @limit].min
      @from = @in.zero? ? 0 : @offset - @outset + 1
      @to   = @offset - @outset + @in
      assign_prev_and_next
      self
    end
  end

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pagy-9.3.3 lib/pagy/countless.rb
pagy-9.3.2 lib/pagy/countless.rb
pagy-9.3.1 lib/pagy/countless.rb
pagy-9.3.0 lib/pagy/countless.rb
pagy-9.2.2 lib/pagy/countless.rb
pagy-9.2.1 lib/pagy/countless.rb
pagy-9.2.0 lib/pagy/countless.rb
pagy-9.1.1 lib/pagy/countless.rb
pagy-9.1.0 lib/pagy/countless.rb
pagy-9.0.9 lib/pagy/countless.rb
pagy-9.0.8 lib/pagy/countless.rb
pagy-9.0.7 lib/pagy/countless.rb
pagy-9.0.6 lib/pagy/countless.rb
pagy-9.0.5 lib/pagy/countless.rb
pagy-9.0.4 lib/pagy/countless.rb
pagy-9.0.3 lib/pagy/countless.rb
pagy-9.0.2 lib/pagy/countless.rb
pagy-9.0.1 lib/pagy/countless.rb
pagy-9.0.0 lib/pagy/countless.rb