Class: ElasticSearchable::Pagination::WillPaginate
- Inherits:
-
ElasticSearchable::Paginator
- Object
- Array
- ElasticSearchable::Paginator
- ElasticSearchable::Pagination::WillPaginate
- Defined in:
- lib/elastic_searchable/pagination/will_paginate.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_entries ⇒ Object
Returns the value of attribute total_entries.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(results, page, per_page, total = nil) ⇒ WillPaginate
constructor
A new instance of WillPaginate.
- #next_page ⇒ Object
- #offset ⇒ Object
- #out_of_bounds? ⇒ Boolean
- #previous_page ⇒ Object
Methods inherited from ElasticSearchable::Paginator
Constructor Details
#initialize(results, page, per_page, total = nil) ⇒ WillPaginate
Returns a new instance of WillPaginate.
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_page ⇒ Object (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_page ⇒ Object (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_entries ⇒ Object
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_pages ⇒ Object (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
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_page ⇒ Object
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 |
#offset ⇒ Object
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
22 23 24 |
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 22 def out_of_bounds? current_page > total_pages end |
#previous_page ⇒ Object
30 31 32 |
# File 'lib/elastic_searchable/pagination/will_paginate.rb', line 30 def previous_page current_page > 1 ? (current_page - 1) : nil end |