Module: Chewy::Query::Pagination::WillPaginate

Extended by:
ActiveSupport::Concern
Includes:
WillPaginate::CollectionMethods
Defined in:
lib/chewy/query/pagination/will_paginate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



8
9
10
# File 'lib/chewy/query/pagination/will_paginate.rb', line 8

def current_page
  @current_page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



8
9
10
# File 'lib/chewy/query/pagination/will_paginate.rb', line 8

def per_page
  @per_page
end

Instance Method Details

#page(page) ⇒ Object



19
20
21
# File 'lib/chewy/query/pagination/will_paginate.rb', line 19

def page(page)
  paginate(page: page)
end

#paginate(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/chewy/query/pagination/will_paginate.rb', line 10

def paginate(options={})
  @current_page = ::WillPaginate::PageNumber(options[:page] || @current_page || 1)
  @page_multiplier = @current_page - 1
  @per_page = (options[:per_page] || @per_page || ::WillPaginate.per_page).to_i

  #call Chewy::Query methods to limit results
  limit(@per_page).offset(@page_multiplier * @per_page)
end