Sha256: 78ebdbd347d54379e749f5761a60994486f7935d93933293f3d1e0171fda866b

Contents?: true

Size: 922 Bytes

Versions: 28

Compression:

Stored size: 922 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, :offset

      def initialize(page = nil, per_page = nil, offset = nil)
        self.offset, self.page, self.per_page = offset, 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

      def offset=(offset)
        @offset = offset.to_i
      end

      private

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

      def rows
        @per_page
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 6 rubygems

Version Path
sunspot-2.1.1 lib/sunspot/query/pagination.rb
sunspot-2.1.0 lib/sunspot/query/pagination.rb
sunspot-2.0.0 lib/sunspot/query/pagination.rb
sunspot-2.0.0.pre.130115 lib/sunspot/query/pagination.rb
gojee-sunspot-2.0.5 lib/sunspot/query/pagination.rb
sunspot-2.0.0.pre.120925 lib/sunspot/query/pagination.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/query/pagination.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/query/pagination.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/query/pagination.rb
gojee-sunspot-2.0.4 lib/sunspot/query/pagination.rb
gojee-sunspot-2.0.2 lib/sunspot/query/pagination.rb
sunspot-2.0.0.pre.120720 lib/sunspot/query/pagination.rb
sunspot-1.3.3 lib/sunspot/query/pagination.rb
sunspot-1.3.2 lib/sunspot/query/pagination.rb
sunspot-2.0.0.pre.120417 lib/sunspot/query/pagination.rb
sunspot-2.0.0.pre.120415 lib/sunspot/query/pagination.rb
sunspot-1.3.1 lib/sunspot/query/pagination.rb
erichummel-sunspot-2.0.0.pre.111215d lib/sunspot/query/pagination.rb
erichummel-sunspot-2.0.0.pre.111215c lib/sunspot/query/pagination.rb
erichummel-sunspot-2.0.0.pre.111215b lib/sunspot/query/pagination.rb