lib/pagy.rb in pagy-8.1.0 vs lib/pagy.rb in pagy-8.1.1

- old
+ new

@@ -3,11 +3,11 @@ require 'pathname' # Core class class Pagy - VERSION = '8.1.0' + VERSION = '8.1.1' # Gem root pathname to get the path of Pagy files stylesheets, javascripts, apps, locales, etc. def self.root @root ||= Pathname.new(__dir__).parent.freeze end @@ -17,14 +17,13 @@ items: 20, outset: 0, size: 7, cycle: false, count_args: [:all], # AR friendly - params: {}, page_param: :page } - attr_reader :count, :page, :items, :vars, :last, :offset, :in, :from, :to, :prev, :next, :params, :request_path + attr_reader :count, :page, :items, :vars, :last, :offset, :in, :from, :to, :prev, :next alias pages last # Merge and validate the options, do some simple arithmetic and set the instance variables def initialize(vars) normalize_vars(vars) @@ -32,13 +31,10 @@ setup_items_var setup_last_var raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last setup_offset_var - setup_params_var - setup_request_path_var - @from = [@offset - @outset + 1, @count].min @to = [@offset - @outset + @items, @count].min @in = [@to - @from + 1, @count].min @prev = (@page - 1 unless @page == 1) @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1 @@ -114,35 +110,19 @@ # Setup @items (overridden by the gearbox extra) def setup_items_var setup_vars(items: 1) end - # Setup @last and @last (overridden by the gearbox extra) + # Setup @last (overridden by the gearbox extra) def setup_last_var @last = [(@count.to_f / @items).ceil, 1].max @last = vars[:max_pages] if vars[:max_pages] && @last > vars[:max_pages] end alias setup_pages_var setup_last_var # Setup @offset based on the :gearbox_items variable def setup_offset_var @offset = (@items * (@page - 1)) + @outset # may be already set from gear_box - end - - # Setup and validate @params - def setup_params_var - raise VariableError.new(self, :params, 'must be a Hash or a Proc', @params) \ - unless (@params = @vars[:params]).is_a?(Hash) || @params.is_a?(Proc) - end - - def setup_request_path_var - request_path = @vars[:request_path] - return if request_path.to_s.empty? - - raise VariableError.new(self, :request_path, 'must be a bare path like "/foo"', request_path) \ - if !request_path.start_with?('/') || request_path.include?('?') - - @request_path = request_path end end require_relative 'pagy/backend' require_relative 'pagy/frontend'