lib/grape/kaminari.rb in grape-kaminari-0.2.1 vs lib/grape/kaminari.rb in grape-kaminari-0.3.0
- old
+ new
@@ -3,10 +3,17 @@
require 'grape/kaminari/max_value_validator'
require 'kaminari/grape'
module Grape
module Kaminari
+ extend ActiveSupport::Concern
+
+ included do
+ helpers HelperMethods
+ base_instance.extend DSLMethods
+ end
+
module HelperMethods # :nodoc:
def paginate(collection)
collection.page(params[:page].to_i)
.per(params[:per_page].to_i)
.padding(params[:offset].to_i)
@@ -20,11 +27,11 @@
header 'X-Offset', params[:offset].to_s
end
end
end
- module ClassMethods # :nodoc:
+ module DSLMethods # :nodoc:
def paginate(**options)
options.reverse_merge!(
per_page: ::Kaminari.config.default_per_page || 10,
max_per_page: ::Kaminari.config.max_per_page,
offset: 0,
@@ -39,13 +46,8 @@
optional :offset, type: Integer, default: options[:offset],
desc: 'Pad a number of results.'
end
end
end
- end
-
- def self.included(base)
- base.helpers HelperMethods
- base.extend ClassMethods
end
end
end