Skip to content

Instantly share code, notes, and snippets.

@arlimus
Created April 10, 2014 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arlimus/10422394 to your computer and use it in GitHub Desktop.
Save arlimus/10422394 to your computer and use it in GitHub Desktop.
Tiny helper to make Sequel look like kaminari to api-pagination.
# 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