Class: ElasticSearchable::Pagination::WillPaginate

Inherits:
ElasticSearchable::Paginator show all
Defined in:
lib/elastic_searchable/pagination/will_paginate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ElasticSearchable::Paginator

handler, handler=, #replace

Constructor Details

#initialize(results, page, per_page, total = nil) ⇒ WillPaginate

Returns a new instance of WillPaginate.

Raises:

  • (InvalidPage)


6
7
8
9
10
11
12
13
14
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 6

def initialize(results, page, per_page, total = nil)
  @current_page = page.to_i
  raise InvalidPage.new(page, @current_page) if @current_page < 1
  @per_page = per_page.to_i
  raise ArgumentError, "`per_page` setting cannot be less than 1 (#{@per_page} given)" if @per_page < 1

  self.total_entries = total if total
  self.replace results
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



4
5
6
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 4

def current_page
  @current_page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



4
5
6
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 4

def per_page
  @per_page
end

#total_entriesObject

Returns the value of attribute total_entries.



4
5
6
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 4

def total_entries
  @total_entries
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



4
5
6
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 4

def total_pages
  @total_pages
end

Class Method Details

.create(page, per_page, total = nil) {|pager| ... } ⇒ Object

Yields:

  • (pager)


16
17
18
19
20
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 16

def self.create(page, per_page, total = nil)
  pager = new(page, per_page, total)
  yield pager
  pager
end

Instance Method Details

#next_pageObject



34
35
36
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 34

def next_page
  current_page < total_pages ? (current_page + 1) : nil
end

#offsetObject



26
27
28
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 26

def offset
  (current_page - 1) * per_page
end

#out_of_bounds?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 22

def out_of_bounds?
  current_page > total_pages
end

#previous_pageObject



30
31
32
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 30

def previous_page
  current_page > 1 ? (current_page - 1) : nil
end