Created
April 10, 2014 20:54
-
-
Save arlimus/10422394 to your computer and use it in GitHub Desktop.
Tiny helper to make Sequel look like kaminari to api-pagination.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage example with Grape: | |
# | |
# require 'kaminari' | |
# require 'sequel-kaminari' | |
# require 'api-pagination' | |
# ... | |
# desc "Get all items" | |
# paginate per_page: 25 | |
# get :items do | |
# paginate( DB[:items] ).all.map(&:to_hash) | |
# end | |
# kaminari wrapper for Sequel | |
module Sequel | |
module DatasetPagination | |
def page( page_no ) | |
@current_page = page_no | |
return paginate( @current_page, @page_size ) if not @page_size.nil? | |
self | |
end | |
def per( page_size ) | |
@page_size = page_size | |
return paginate( @current_page, @page_size ) if not @current_page.nil? | |
self | |
end | |
end | |
class Dataset | |
module Pagination | |
alias :total_pages :page_count | |
alias :total_count :pagination_record_count | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment