-
Notifications
You must be signed in to change notification settings - Fork 533
Strict None Paginator
Benjamin Fleischer edited this page Jun 10, 2019
·
1 revision
Define a strict_none paginator. Nothing when offset > 0
Avoids possibly infinite pagination bugs
JSONAPI.configure do |config|
config.default_paginator = :offset
# NOTE: If we're not going to show the number, be sure
# to use the paginator :strict_none
config.top_level_links_include_pagination = false
end
app/models/strict_none_paginator.rb
# frozen_string_literal: true
# Usage in resource:
# paginator :strict_none
#
require 'jsonapi/paginator'
class StrictNonePaginator < OffsetPaginator
# attr_reader :limit, :offset
def self.requires_record_count
false
end
def apply(relation, _order_options)
if @offset > 0
relation.respond_to?(:none, true) ? relation.none : []
else
relation
end
end
end