Class: ROM::SQL::Plugin::Pagination::Pager
- Inherits:
-
Object
- Object
- ROM::SQL::Plugin::Pagination::Pager
- Extended by:
- Initializer
- Defined in:
- lib/rom/sql/plugin/pagination.rb
Instance Method Summary collapse
- #at(dataset, current_page, per_page = self.per_page) ⇒ Object
- #next_page ⇒ Object
- #prev_page ⇒ Object
- #total ⇒ Object
- #total_pages ⇒ Object
Instance Method Details
#at(dataset, current_page, per_page = self.per_page) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/rom/sql/plugin/pagination.rb', line 34 def at(dataset, current_page, per_page = self.per_page) current_page = current_page.to_i per_page = per_page.to_i self.class.new( dataset.offset((current_page-1)*per_page).limit(per_page), current_page: current_page, per_page: per_page ) end |
#next_page ⇒ Object
16 17 18 19 |
# File 'lib/rom/sql/plugin/pagination.rb', line 16 def next_page num = current_page + 1 num if total_pages >= num end |
#prev_page ⇒ Object
21 22 23 24 |
# File 'lib/rom/sql/plugin/pagination.rb', line 21 def prev_page num = current_page - 1 num if num > 0 end |
#total ⇒ Object
26 27 28 |
# File 'lib/rom/sql/plugin/pagination.rb', line 26 def total dataset.unlimited.count end |
#total_pages ⇒ Object
30 31 32 |
# File 'lib/rom/sql/plugin/pagination.rb', line 30 def total_pages (total / per_page.to_f).ceil end |