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'
2
1
require 'api-pagination/version'
3
2
4
3
module ApiPagination
@@ -19,6 +18,8 @@ def paginate(collection, options = {})
19
18
else
20
19
collection . paginate ( :page => options [ :page ] , :per_page => options [ :per_page ] )
21
20
end
21
+ else
22
+ fail StandardError , "Unknown paginator: #{ ApiPagination . paginator } "
22
23
end
23
24
end
24
25
@@ -44,3 +45,5 @@ def total_from(collection)
44
45
end
45
46
end
46
47
end
48
+
49
+ require 'api-pagination/hooks'
Original file line number Diff line number Diff line change @@ -18,20 +18,26 @@ def self.init!
18
18
require 'grape/pagination'
19
19
Grape ::API . send ( :include , Grape ::Pagination )
20
20
end
21
-
22
21
# Kaminari and will_paginate conflict with each other, so we should check
23
22
# 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 )
25
30
initialize_kaminari! and return
26
31
elsif defined? ( WillPaginate ::CollectionMethods )
27
32
initialize_will_paginate! and return
28
33
end
29
-
30
34
# 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
35
41
end
36
42
37
43
begin
@@ -65,4 +71,8 @@ def last_page?() !next_page end
65
71
end
66
72
end
67
73
74
+ if ENV [ 'PAGINATOR' ]
75
+ ApiPagination . instance_variable_set ( :@paginator , ENV [ 'PAGINATOR' ] . to_sym )
76
+ end
77
+
68
78
ApiPagination ::Hooks . init!
You can’t perform that action at this time.
0 commit comments