Module: ROM::SQL::Plugin::Pagination
- Defined in:
- lib/rom/sql/plugin/pagination.rb
Defined Under Namespace
Classes: Pager
Class Method Summary collapse
Instance Method Summary collapse
-
#page(num) ⇒ Relation
Paginate a relation.
-
#per_page(num) ⇒ Object
Set limit for pagination.
Class Method Details
.included(klass) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rom/sql/plugin/pagination.rb', line 47 def self.included(klass) super klass.class_eval do defines :per_page option :pager, reader: true, default: proc { |relation| Pager.new(relation.dataset, per_page: relation.class.per_page) } end end |
Instance Method Details
#page(num) ⇒ Relation
Paginate a relation
69 70 71 72 |
# File 'lib/rom/sql/plugin/pagination.rb', line 69 def page(num) next_pager = pager.at(dataset, num) new(next_pager.dataset, pager: next_pager) end |
#per_page(num) ⇒ Object
Set limit for pagination
80 81 82 83 |
# File 'lib/rom/sql/plugin/pagination.rb', line 80 def per_page(num) next_pager = pager.at(dataset, pager.current_page, num) new(next_pager.dataset, pager: next_pager) end |