lib/pagy.rb in pagy-0.7.2 vs lib/pagy.rb in pagy-0.8.0

- old
+ new

@@ -1,30 +1,27 @@ # See Pagy API documentation: https://ddnexus.github.io/pagy/api/pagy require 'pathname' -class Pagy ; VERSION = '0.7.2' +class Pagy ; VERSION = '0.8.0' - autoload :Backend, 'pagy/backend' - autoload :Frontend, 'pagy/frontend' - class OutOfRangeError < StandardError; end # root pathname to get the path of pagy files like templates or dictionaries def self.root; Pathname.new(__FILE__).dirname end # default core vars - VARS = { page:1, items:20, outset:0, size:[1,4,4,1] } + VARS = { page:1, items:20, outset:0, size:[1,4,4,1], page_param: :page } # default I18n vars zero_one = [:zero, :one] ; I18N = { file: Pagy.root.join('locales', 'pagy.yml').to_s, plurals: -> (c) {(zero_one[c] || :other).to_s.freeze} } attr_reader :count, :page, :items, :vars, :pages, :last, :offset, :from, :to, :prev, :next # merge and validate the options, do some simple aritmetic and set the instance variables def initialize(vars) - @vars = VARS.merge(vars.delete_if{|k,v| v.nil? || v == '' }) # default vars + cleaned instance vars + @vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned instance vars { count:0, items:1, outset:0, page:1 }.each do |k,min| # validate core variables (@vars[k] && instance_variable_set(:"@#{k}", @vars.delete(k).to_i) >= min) \ or raise(ArgumentError, "expected :#{k} >= #{min}; got #{instance_variable_get(:"@#{k}").inspect}") end @pages = @last = [(@count.to_f / @items).ceil, 1].max # cardinal and ordinal meanings @@ -50,5 +47,8 @@ end # shift the start boundary (0) and series.tap{|s| s.shift; s[s.index(@page)] = @page.to_s} # convert the current page to String end end + +require 'pagy/backend' +require 'pagy/frontend'