Sha256: 7c2eeb7d69b3b9762842e3d429355cec1d21e8d349ff87712cc19c544e515020

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

class ThinkingSphinx::Masks::PaginationMask
  def initialize(search)
    @search = search
  end

  def can_handle?(method)
    public_methods(false).include?(method)
  end

  def first_page?
    search.current_page == 1
  end

  def last_page?
    next_page.nil?
  end

  def next_page
    search.current_page >= total_pages ? nil : search.current_page + 1
  end

  def next_page?
    !next_page.nil?
  end

  def page(number)
    search.options[:page] = number
    search
  end

  def per(limit)
    search.options[:limit] = limit
    search
  end

  def previous_page
    search.current_page == 1 ? nil : search.current_page - 1
  end

  def total_entries
    search.meta['total_found'].to_i
  end

  alias_method :total_count, :total_entries
  alias_method :count,       :total_entries

  def total_pages
    return 0 if search.meta['total'].nil?

    @total_pages ||= (search.meta['total'].to_i / search.per_page.to_f).ceil
  end

  alias_method :page_count, :total_pages
  alias_method :num_pages,  :total_pages

  private

  attr_reader :search
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
thinking-sphinx-3.1.3 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.1.2 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.1.1 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.1.0 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.0.6 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.0.5 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.0.4 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.0.3 lib/thinking_sphinx/masks/pagination_mask.rb