Sha256: 76c079749547ef37a8a9a6ec4fb431697c59037fb0b72b13703d9a7eb9880475

Contents?: true

Size: 801 Bytes

Versions: 37

Compression:

Stored size: 801 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(page = nil, per_page = nil)
        self.page, self.per_page = page, per_page
      end

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

      def page=(page)
        @page = page.to_i if page
      end

      def per_page=(per_page)
        @per_page = per_page.to_i if per_page
      end

      private

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

      def rows
        @per_page
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 9 rubygems

Version Path
pduey-sunspot-1.2.1.1 lib/sunspot/query/pagination.rb
erichummel-sunspot-1.2.1g lib/sunspot/query/pagination.rb
erichummel-sunspot-1.2.1f lib/sunspot/query/pagination.rb
erichummel-sunspot-1.2.1b lib/sunspot/query/pagination.rb
erichummel-sunspot-1.2.1a lib/sunspot/query/pagination.rb
erichummel-sunspot-1.2.1 lib/sunspot/query/pagination.rb
lisausa-sunspot-1.2.1.1 lib/sunspot/query/pagination.rb
lisausa-sunspot-1.2.1 lib/sunspot/query/pagination.rb
sunspot_rbg-1.3.1 lib/sunspot/query/pagination.rb
sunspot_rbg-1.3.0 lib/sunspot/query/pagination.rb
ruben-sunspot-1.1.4 lib/sunspot/query/pagination.rb
ruben-sunspot-1.1.3 lib/sunspot/query/pagination.rb
ruben-sunspot-1.1.2 lib/sunspot/query/pagination.rb
sunspot-1.2.1 lib/sunspot/query/pagination.rb
sunspot-1.2.0 lib/sunspot/query/pagination.rb
ruben-sunspot-1.1.1 lib/sunspot/query/pagination.rb
ruben-sunspot-1.1.0 lib/sunspot/query/pagination.rb
nuatt_sunspot-1.1.0.3 lib/sunspot/query/pagination.rb
sunspot-1.1.0 lib/sunspot/query/pagination.rb
sunspot-1.0.5 lib/sunspot/query/pagination.rb