Sha256: 98fcebf28754675cfa06ef58c29046a872d3115b132f91ae08f83125495b3324

Contents?: true

Size: 876 Bytes

Versions: 17

Compression:

Stored size: 876 Bytes

Contents

module Sunspot
  module Query
    # 
    # A query component that holds information about pagination. Unlike other
    # query components, this one is mutable, because the query itself holds a
    # reference to it and updates it if pagination is changed.
    #
    class Pagination #:nodoc:
      attr_reader :page, :per_page

      def initialize(configuration, page = nil, per_page = nil)
        @configuration = configuration
        self.page, self.per_page = page, per_page
      end

      def to_params
        { :start => start, :rows => rows }
      end

      def page=(page)
        @page = page || 1
      end

      def per_page=(per_page)
        @per_page = per_page || @configuration.pagination.default_per_page
      end

      private

      def start
        (@page - 1) * @per_page
      end

      def rows
        @per_page
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 6 rubygems

Version Path
Chrononaut-sunspot-client-0.9.4 lib/sunspot/query/pagination.rb
UnderpantsGnome-sunspot-0.9.1.1 lib/sunspot/query/pagination.rb
UnderpantsGnome-sunspot-0.9.8.1 lib/sunspot/query/pagination.rb
kristopher-sunspot-0.9.8 lib/sunspot/query/pagination.rb
kuahyeow-sunspot-0.9.7 lib/sunspot/query/pagination.rb
kuahyeow-sunspot-0.9.8 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.0 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.1 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.2 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.3 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.4 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.5 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.6 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.7 lib/sunspot/query/pagination.rb
outoftime-sunspot-0.9.8 lib/sunspot/query/pagination.rb
sunspot-0.9.8 lib/sunspot/query/pagination.rb
sunspot-0.9.7 lib/sunspot/query/pagination.rb