lib/pagy/countless.rb in pagy-1.3.3 vs lib/pagy/countless.rb in pagy-2.0.0

- old
+ new

@@ -1,13 +1,16 @@ +# encoding: utf-8 +# frozen_string_literal: true + require 'pagy' class Pagy class Countless < Pagy # Merge and validate the options, do some simple arithmetic and set a few instance variables def initialize(vars={}) - @vars ||= VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden) + @vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden) { items:1, outset:0, page:1 }.each do |k,min| # validate instance variables (@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \ or raise(ArgumentError, "expected :#{k} >= #{min}; got #{@vars[k].inspect}") end @offset = @items * (@page - 1) + @outset # pagination offset + outset (initial offset)