@@ -17,15 +17,15 @@ def configure(&block)
1717 end
1818
1919 def initialize
20- @total_header = ' Total'
21- @per_page_header = ' Per-Page'
22- @page_header = nil
23- @include_total = true
24- @base_url = nil
20+ @total_header = " Total"
21+ @per_page_header = " Per-Page"
22+ @page_header = nil
23+ @include_total = true
24+ @base_url = nil
2525 @response_formats = [ :json , :xml ]
2626 end
2727
28- [ ' page' , ' per_page' ] . each do |param_name |
28+ [ " page" , " per_page" ] . each do |param_name |
2929 method_name = "#{ param_name } _param"
3030 instance_variable_name = "@#{ method_name } "
3131
@@ -37,15 +37,15 @@ def initialize
3737
3838 if instance_variable_get ( instance_variable_name ) . nil?
3939 # use :page & :per_page by default
40- instance_variable_set ( instance_variable_name , ( lambda { |p | p [ param_name . to_sym ] } ) )
40+ instance_variable_set ( instance_variable_name , lambda { |p | p [ param_name . to_sym ] } )
4141 end
4242
4343 instance_variable_get ( instance_variable_name ) . call ( params )
4444 end
4545
4646 define_method "#{ method_name } =" do |param |
4747 if param . is_a? ( Symbol ) || param . is_a? ( String )
48- instance_variable_set ( instance_variable_name , ( lambda { |params | params [ param ] } ) )
48+ instance_variable_set ( instance_variable_name , lambda { |params | params [ param ] } )
4949 else
5050 raise ArgumentError , "Cannot set page_param option"
5151 end
@@ -78,24 +78,24 @@ def paginator=(paginator)
7878 def set_paginator
7979 conditions = [ defined? ( Pagy ) , defined? ( Kaminari ) , defined? ( WillPaginate ::CollectionMethods ) ]
8080 if conditions . compact . size > 1
81- Kernel . warn <<- WARNING
82- Warning: api-pagination relies on Pagy, Kaminari, or WillPaginate, but more than
83- one are currently active. If possible, you should remove one or the other. If
84- you can't, you _must_ configure api-pagination on your own. For example:
85-
86- ApiPagination.configure do |config|
87- config.paginator = :kaminari
88- end
89-
90- You should also configure Kaminari to use a different `per_page` method name as
91- using these gems together causes a conflict; some information can be found at
92- https://github.com/activeadmin/activeadmin/wiki/How-to-work-with-will_paginate
93-
94- Kaminari.configure do |config|
95- config.page_method_name = :per_page_kaminari
96- end
97-
98- WARNING
81+ Kernel . warn <<~ WARNING
82+ Warning: api-pagination relies on Pagy, Kaminari, or WillPaginate, but more than
83+ one are currently active. If possible, you should remove one or the other. If
84+ you can't, you _must_ configure api-pagination on your own. For example:
85+
86+ ApiPagination.configure do |config|
87+ config.paginator = :kaminari
88+ end
89+
90+ You should also configure Kaminari to use a different `per_page` method name as
91+ using these gems together causes a conflict; some information can be found at
92+ https://github.com/activeadmin/activeadmin/wiki/How-to-work-with-will_paginate
93+
94+ Kaminari.configure do |config|
95+ config.page_method_name = :per_page_kaminari
96+ end
97+
98+ WARNING
9999 elsif defined? ( Pagy )
100100 use_pagy
101101 elsif defined? ( Kaminari )
@@ -110,14 +110,19 @@ def use_pagy
110110 end
111111
112112 def use_kaminari
113- require ' kaminari/models/array_extension'
113+ require " kaminari/models/array_extension"
114114 @paginator = :kaminari
115115 end
116116
117117 def use_will_paginate
118118 WillPaginate ::CollectionMethods . module_eval do
119- def first_page? ( ) !previous_page end
120- def last_page? ( ) !next_page end
119+ def first_page?
120+ !previous_page
121+ end
122+
123+ def last_page?
124+ !next_page
125+ end
121126 end
122127
123128 @paginator = :will_paginate
@@ -132,6 +137,6 @@ def configure
132137 def config
133138 @config ||= Configuration . new
134139 end
135- alias :configuration :config
140+ alias_method :configuration , :config
136141 end
137142end
0 commit comments