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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rom/sql/plugin/pagination.rb', line 50 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
72 73 74 75 |
# File 'lib/rom/sql/plugin/pagination.rb', line 72 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
83 84 85 86 |
# File 'lib/rom/sql/plugin/pagination.rb', line 83 def per_page(num) next_pager = pager.at(dataset, pager.current_page, num) __new__(next_pager.dataset, pager: next_pager) end |