Sha256: 7e15fc45621a94401314c0f907827f9444dd54e002a5491dee5dee71dba5e36f

Contents?: true

Size: 1.11 KB

Versions: 16

Compression:

Stored size: 1.11 KB

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, :cursor

      def initialize(page = nil, per_page = nil, offset = nil, cursor = nil)
        self.offset, self.page, self.per_page, self.cursor = offset, page, per_page, cursor
      end

      def to_params
        if @cursor
          { :cursorMark => @cursor, :rows => rows }
        else
          { :start => start, :rows => rows }
        end
      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

      def cursor=(cursor)
        @cursor = cursor if cursor
      end

      private

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

      def rows
        @per_page
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
sunspot-2.7.1 lib/sunspot/query/pagination.rb
sunspot-2.7.0 lib/sunspot/query/pagination.rb
sunspot-2.6.0 lib/sunspot/query/pagination.rb
sunspot-2.5.0 lib/sunspot/query/pagination.rb
sunspot-2.4.0 lib/sunspot/query/pagination.rb
sunspot-2.3.0 lib/sunspot/query/pagination.rb
sunspot-2.2.8 lib/sunspot/query/pagination.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/lib/sunspot/query/pagination.rb
sunspot-2.2.7 lib/sunspot/query/pagination.rb
sunspot-2.2.6 lib/sunspot/query/pagination.rb
sunspot-2.2.5 lib/sunspot/query/pagination.rb
sunspot-2.2.4 lib/sunspot/query/pagination.rb
sunspot-2.2.3 lib/sunspot/query/pagination.rb
sunspot-2.2.2 lib/sunspot/query/pagination.rb
sunspot-2.2.1 lib/sunspot/query/pagination.rb
sunspot-2.2.0 lib/sunspot/query/pagination.rb