File tree Expand file tree Collapse file tree 2 files changed +21
-8
lines changed
Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change 1- require 'api-pagination/hooks'
21require 'api-pagination/version'
32
43module ApiPagination
@@ -19,6 +18,8 @@ def paginate(collection, options = {})
1918 else
2019 collection . paginate ( :page => options [ :page ] , :per_page => options [ :per_page ] )
2120 end
21+ else
22+ fail StandardError , "Unknown paginator: #{ ApiPagination . paginator } "
2223 end
2324 end
2425
@@ -44,3 +45,5 @@ def total_from(collection)
4445 end
4546 end
4647end
48+
49+ require 'api-pagination/hooks'
Original file line number Diff line number Diff line change @@ -18,20 +18,26 @@ def self.init!
1818 require 'grape/pagination'
1919 Grape ::API . send ( :include , Grape ::Pagination )
2020 end
21-
2221 # Kaminari and will_paginate conflict with each other, so we should check
2322 # to see if either is already active before attempting to load them.
24- if defined? ( Kaminari )
23+ if defined? ( Kaminari ) && defined? ( WillPaginate ::CollectionMethods )
24+ STDERR . puts <<-EOC
25+ Warning: api-pagination relies on either Kaminari or WillPaginate, but these
26+ gems conflict. Please ensure only one of them is active at any given time.
27+ EOC
28+ return
29+ elsif defined? ( Kaminari )
2530 initialize_kaminari! and return
2631 elsif defined? ( WillPaginate ::CollectionMethods )
2732 initialize_will_paginate! and return
2833 end
29-
3034 # If neither is loaded, we can safely attempt these requires.
31- begin
32- require 'kaminari'
33- initialize_kaminari! and return
34- rescue LoadError
35+ unless ApiPagination . paginator == :will_paginate
36+ begin
37+ require 'kaminari'
38+ initialize_kaminari! and return
39+ rescue LoadError
40+ end
3541 end
3642
3743 begin
@@ -65,4 +71,8 @@ def last_page?() !next_page end
6571 end
6672end
6773
74+ if ENV [ 'PAGINATOR' ]
75+ ApiPagination . instance_variable_set ( :@paginator , ENV [ 'PAGINATOR' ] . to_sym )
76+ end
77+
6878ApiPagination ::Hooks . init!
You can’t perform that action at this time.
0 commit comments