Class: Hanami::Pagination::Pager

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/pagination/pager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pager) ⇒ Pager

Returns a new instance of Pager.



6
7
8
# File 'lib/hanami/pagination/pager.rb', line 6

def initialize(pager)
  @pager = pager
end

Instance Attribute Details

#pagerObject (readonly)

Returns the value of attribute pager.



4
5
6
# File 'lib/hanami/pagination/pager.rb', line 4

def pager
  @pager
end

Instance Method Details

#all_pagesObject



44
45
46
# File 'lib/hanami/pagination/pager.rb', line 44

def all_pages
  (1..pager.total_pages).to_a
end

#current_pageObject



26
27
28
# File 'lib/hanami/pagination/pager.rb', line 26

def current_page
  pager.current_page
end

#current_page?(page) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/hanami/pagination/pager.rb', line 30

def current_page?(page)
  pager.current_page == page
end

#first_page?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/hanami/pagination/pager.rb', line 48

def first_page?
  pager.current_page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/hanami/pagination/pager.rb', line 52

def last_page?
  pager.current_page == pager.total_pages
end

#next_pageObject



10
11
12
# File 'lib/hanami/pagination/pager.rb', line 10

def next_page
  pager.next_page
end

#pages_range(delta: 3) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/hanami/pagination/pager.rb', line 34

def pages_range(delta: 3)
  first = pager.current_page - delta
  first = first > 0 ? first : 1

  last = pager.current_page + delta
  last = last < pager.total_pages ? last : pager.total_pages

  (first..last).to_a
end

#prev_pageObject



14
15
16
# File 'lib/hanami/pagination/pager.rb', line 14

def prev_page
  pager.prev_page
end

#totalObject



18
19
20
# File 'lib/hanami/pagination/pager.rb', line 18

def total
  pager.total
end

#total_pagesObject



22
23
24
# File 'lib/hanami/pagination/pager.rb', line 22

def total_pages
  pager.total_pages
end