Skip to content

Commit

Permalink
use case (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser authored and ddnexus committed Jul 14, 2018
1 parent 36761a8 commit 48fa056
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/pagy/extras/out_of_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 48fa056

Please sign in to comment.