Class: ROM::SQL::Plugin::Pagination::Pager

Inherits:
Object
  • Object
show all
Extended by:
Initializer
Defined in:
lib/rom/sql/plugin/pagination.rb

Instance Method Summary collapse

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_pageObject



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_pageObject



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

#totalObject



26
27
28
# File 'lib/rom/sql/plugin/pagination.rb', line 26

def total
  dataset.unlimited.count
end

#total_pagesObject



30
31
32
# File 'lib/rom/sql/plugin/pagination.rb', line 30

def total_pages
  (total / per_page.to_f).ceil
end