Module: ROM::LDAP::Plugin::Pagination

Defined in:
lib/rom/ldap/plugin/pagination.rb

Overview

Pagination plugin for Relations

Defined Under Namespace

Classes: Pager

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rom/ldap/plugin/pagination.rb', line 98

def self.included(klass)
  super

  klass.class_eval do
    defines :per_page

    option :pager, default: -> {
      Pager.new(dataset, per_page: self.class.per_page)
    }
  end
end

Instance Method Details

#page(num) ⇒ Relation

Paginate a relation

Examples:

users.page(1)
users.pager # => info about pagination

Returns:



119
120
121
122
# File 'lib/rom/ldap/plugin/pagination.rb', line 119

def page(num)
  next_pager = pager.at(dataset, num)
  new(next_pager.dataset, pager: next_pager)
end

#per_page(num) ⇒ Relation

Set limit for pagination

Examples:

users.per_page(10).page(2)

Returns:



132
133
134
135
# File 'lib/rom/ldap/plugin/pagination.rb', line 132

def per_page(num)
  next_pager = pager.at(dataset, pager.current_page, num)
  new(next_pager.dataset, pager: next_pager)
end