Permalink
Browse files

Merge pull request #63 from chytreg/master

Add kaminari for pagination
  • Loading branch information...
adelevie committed Feb 8, 2013
2 parents c40fe98 + 1155223 commit 1d5d5256ccc4370b848ac8731c7de02fe3ffd176
Showing with 39 additions and 0 deletions.
  1. +38 −0 lib/kaminari_extension.rb
  2. +1 −0 lib/parse_resource.rb
View
@@ -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)

This comment has been minimized.

Show comment Hide comment
@chytreg

chytreg Feb 8, 2013

Collaborator

This should be at the top of the file and wrap whole module. Since we try to include Kaminari::ConfigurationMethods which is kaminari specific. This the reason of test failing.

@chytreg

chytreg Feb 8, 2013

Collaborator

This should be at the top of the file and wrap whole module. Since we try to include Kaminari::ConfigurationMethods which is kaminari specific. This the reason of test failing.

This comment has been minimized.

Show comment Hide comment
@jamonholmgren

jamonholmgren Feb 8, 2013

Collaborator

Makes sense.

@jamonholmgren

jamonholmgren Feb 8, 2013

Collaborator

Makes sense.

This comment has been minimized.

Show comment Hide comment
@adelevie

adelevie Feb 8, 2013

Owner

So is it just a matter of including this in the setup block of a test case?

@adelevie

adelevie Feb 8, 2013

Owner

So is it just a matter of including this in the setup block of a test case?

This comment has been minimized.

Show comment Hide comment
@chytreg

chytreg Feb 8, 2013

Collaborator
+ ParseResource::Base.send :include, KaminariExtension::ParseBaseExt
+ Query.send :include, KaminariExtension::QueryExt
+end
View
@@ -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

0 comments on commit 1d5d525

Please sign in to comment.