Sha256: 7543197848fa74d9abd716a1cd62f006d2aad146475123a875d8f4be50693882

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 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

  alias_method :prev_page, :previous_page

  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

6 entries across 6 versions & 1 rubygems

Version Path
thinking-sphinx-3.4.2 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.4.1 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.4.0 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.3.0 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.2.0 lib/thinking_sphinx/masks/pagination_mask.rb
thinking-sphinx-3.1.4 lib/thinking_sphinx/masks/pagination_mask.rb