From 48fa05622c95ac2de93dd43dc9e7d339a16685ea Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Sat, 14 Jul 2018 08:47:24 +0200 Subject: [PATCH] use case (#71) --- lib/pagy/extras/out_of_range.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/pagy/extras/out_of_range.rb b/lib/pagy/extras/out_of_range.rb index 92cf17f6b..319e9286b 100644 --- a/lib/pagy/extras/out_of_range.rb +++ b/lib/pagy/extras/out_of_range.rb @@ -8,18 +8,21 @@ module OutOfRange def initialize(vars) super - rescue OutOfRangeError => e + rescue OutOfRangeError @out_of_range = true # adds the out_of_range flag - raise e if @vars[:out_of_range_mode] == :exception - if @vars[:out_of_range_mode] == :last_page + case @vars[:out_of_range_mode] + when :exception + raise + when :last_page page = @vars[:page] # save the very initial page (even after re-run) super(vars.merge!(page: @last)) # re-run with the last page @vars[:page] = page # restore the inital page - elsif @vars[:out_of_range_mode] == :empty_page + when :empty_page @offset = @items = @from = @to = 0 # vars relative to the actual page @prev = @last extend(Series) - else raise ArgumentError, "Unknown mode #{@vars[:out_of_range_mode]}" + else + raise ArgumentError, "Unknown mode #{@vars[:out_of_range_mode]}" end end