Module: ROM::SQL::Plugin::Pagination
- Defined in:
- lib/rom/sql/plugin/pagination.rb
Overview
Pagination plugin for Relations
Defined Under Namespace
Classes: Pager
Class Method Summary collapse
- .included(klass) ⇒ Object private
Instance Method Summary collapse
-
#page(num) ⇒ Relation
Paginate a relation.
-
#per_page(num) ⇒ Relation
Set limit for pagination.
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.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rom/sql/plugin/pagination.rb', line 90 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
111 112 113 114 |
# File 'lib/rom/sql/plugin/pagination.rb', line 111 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
124 125 126 127 |
# File 'lib/rom/sql/plugin/pagination.rb', line 124 def per_page(num) next_pager = pager.at(dataset, pager.current_page, num) new(next_pager.dataset, pager: next_pager) end |