Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add kaminari for pagination

  • Loading branch information...
commit 1155223134b5f2d922c48c7b50bc6f63c3715264 1 parent c40fe98
@chytreg chytreg authored
Showing with 39 additions and 0 deletions.
  1. +38 −0 lib/kaminari_extension.rb
  2. +1 −0  lib/parse_resource.rb
View
38 lib/kaminari_extension.rb
@@ -0,0 +1,38 @@
+module KaminariExtension
+ module ParseBaseExt
+ extend ActiveSupport::Concern
+ include Kaminari::ConfigurationMethods
+
+ module ClassMethods
+ def page(num)
+ Query.new(self).limit(default_per_page).skip(default_per_page * ([num.to_i, 1].max - 1))
+ end
+ end
+ end
+
+ module QueryExt
+ extend ActiveSupport::Concern
+ include Kaminari::PageScopeMethods
+
+ included do
+ alias :offset :skip
+ end
+
+ def limit_value
+ criteria[:limit]
+ end
+
+ def offset_value
+ criteria[:skip]
+ end
+
+ def total_count
+ count
+ end
+ end
+end
+
+if defined?(Kaminari)
+ ParseResource::Base.send :include, KaminariExtension::ParseBaseExt
+ Query.send :include, KaminariExtension::QueryExt
+end
View
1  lib/parse_resource.rb
@@ -5,6 +5,7 @@
require 'parse_resource/parse_user'
require 'parse_resource/parse_user_validator'
require 'parse_resource/parse_error'
+require 'kaminari_extension'
module ParseResource
Please sign in to comment.
Something went wrong with that request. Please try again.