File tree Expand file tree Collapse file tree 2 files changed +20
-23
lines changed Expand file tree Collapse file tree 2 files changed +20
-23
lines changed Original file line number Diff line number Diff line change 1
- begin ; require 'rails' ; rescue LoadError ; end
2
- begin ; require 'rails-api' ; rescue LoadError ; end
3
-
4
- if defined? ( Rails )
5
- module ApiPagination
6
- module Hooks
7
- def self . rails_parent_controller
8
- if Gem ::Version . new ( Rails . version ) >= Gem ::Version . new ( '5' ) || defined? ( ActionController ::API )
9
- ActionController ::API
10
- else
11
- ActionController ::Base
12
- end
13
- end
14
- end
15
- end
16
-
17
- require 'rails/pagination'
18
-
19
- ActiveSupport . on_load ( :action_controller ) do
20
- ApiPagination ::Hooks . rails_parent_controller . send ( :include , Rails ::Pagination )
21
- end
22
- end
23
-
24
1
begin ; require 'grape' ; rescue LoadError ; end
25
2
if defined? ( Grape ::API )
26
3
require 'grape/pagination'
@@ -40,3 +17,4 @@ def self.rails_parent_controller
40
17
WARNING
41
18
end
42
19
20
+ require 'api-pagination/railtie' if defined? ( Rails )
Original file line number Diff line number Diff line change
1
+ require 'rails/railtie'
2
+
3
+ module ApiPagination
4
+ class Railtie < ::Rails ::Railtie
5
+ initializer :api_pagination do
6
+ ActiveSupport . on_load ( :action_controller ) do
7
+ require 'rails/pagination'
8
+
9
+ klass = if Rails ::VERSION ::MAJOR >= 5 || defined? ( ActionController ::API )
10
+ ActionController ::API
11
+ else
12
+ ActionController ::Base
13
+ end
14
+
15
+ klass . send ( :include , Rails ::Pagination )
16
+ end
17
+ end
18
+ end
19
+ end
You can’t perform that action at this time.
0 commit comments