File: sequel.rb

package info (click to toggle)
ruby-will-paginate 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: ruby: 2,940; sh: 50; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 782 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'sequel'
require 'sequel/extensions/pagination'
require 'will_paginate/collection'

module WillPaginate
  # Sequel already supports pagination; we only need to make the
  # resulting dataset look a bit more like WillPaginate::Collection
  module SequelMethods
    include WillPaginate::CollectionMethods

    def total_pages
      page_count
    end

    def per_page
      page_size
    end

    def size
      current_page_record_count
    end
    alias length size

    def total_entries
      pagination_record_count
    end

    def out_of_bounds?
      current_page > total_pages
    end

    # Current offset of the paginated collection
    def offset
      (current_page - 1) * per_page
    end
  end

  Sequel::Dataset::Pagination.send(:include, SequelMethods)
end