@@ -4,11 +4,20 @@ module Support
44 module Pagination
55 RecordCountError = Class . new ( ArgumentError )
66
7+ # Check whether pagination links should be included.
8+ #
9+ # @api public
10+ # @return [Boolean]
711 def include_pagination_links?
812 JSONAPI . configuration . default_paginator != :none &&
913 JSONAPI . configuration . top_level_links_include_pagination
1014 end
1115
16+ # Check whether pagination's page count should be included
17+ # on the "meta" key.
18+ #
19+ # @api public
20+ # @return [Boolean]
1221 def include_page_count?
1322 JSONAPI . configuration . top_level_meta_include_page_count
1423 end
@@ -18,15 +27,17 @@ def include_page_count?
1827 # @param records [ActiveRecord::Relation, Array] collection of records
1928 # e.g.: User.all or [{ id: 1, name: 'Tiago' }, { id: 2, name: 'Doug' }]
2029 #
21- # @param options [Hash] JU's options
30+ # @param options [Hash] JSONAPI::Utils' options
2231 # e.g.: { resource: V2::UserResource, count: 100 }
2332 #
2433 # @return [ActiveRecord::Relation, Array]
2534 #
2635 # @api public
2736 def apply_pagination ( records , options = { } )
28- return records unless apply_pagination? ( options )
29- records . is_a? ( Array ) ? records [ paginate_with ( :range ) ] : paginate_with ( :paginator ) . apply ( records , nil )
37+ if !apply_pagination? ( options ) then records
38+ elsif records . is_a? ( Array ) then records [ paginate_with ( :range ) ]
39+ else paginate_with ( :paginator ) . apply ( records , nil )
40+ end
3041 end
3142
3243 # Mount pagination params for JSONAPI::ResourcesOperationResult.
@@ -44,7 +55,7 @@ def apply_pagination(records, options = {})
4455 #
4556 # @api public
4657 def pagination_params ( records , options )
47- return { } unless JSONAPI . configuration . top_level_links_include_pagination
58+ return { } unless include_pagination_links?
4859 paginator . links_page_params ( record_count : record_count_for ( records , options ) )
4960 end
5061
0 commit comments