Module: Esse::WillPaginate::Pagination::SearchQuery

Defined in:
lib/esse/will_paginate/pagination.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/esse/will_paginate/pagination.rb', line 7

def self.included(base)
  base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
    # Define the `paginate` WillPaginate method
    #
    # @param [Hash] options
    # @option options [Integer] :page
    # @option options [Integer] :per_page
    # @return [Esse::WillPaginate::SearchQuery]
    def paginate(options = {})
      curr_page = ::WillPaginate::PageNumber(options[:page] || 1)
      limit_val = (options[:per_page] || ::WillPaginate.per_page).to_i
      offset_val = (curr_page - 1) * limit_val
      limit(limit_val).offset(offset_val)
    end
  RUBY
end

Instance Method Details

#paginated_resultsObject



24
25
26
27
28
29
# File 'lib/esse/will_paginate/pagination.rb', line 24

def paginated_results
  page = (offset_value / limit_value.to_f).ceil + 1
  ::WillPaginate::Collection.create(page, limit_value, response.total) do |pager|
    pager.replace response.hits
  end
end