Class: Sunspot::Query::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/query/pagination.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page = nil, per_page = nil, offset = nil, cursor = nil) ⇒ Pagination

Returns a new instance of Pagination.



11
12
13
# File 'lib/sunspot/query/pagination.rb', line 11

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

Instance Attribute Details

#cursorObject

:nodoc:



9
10
11
# File 'lib/sunspot/query/pagination.rb', line 9

def cursor
  @cursor
end

#offsetObject

:nodoc:



9
10
11
# File 'lib/sunspot/query/pagination.rb', line 9

def offset
  @offset
end

#pageObject

:nodoc:



9
10
11
# File 'lib/sunspot/query/pagination.rb', line 9

def page
  @page
end

#per_pageObject

:nodoc:



9
10
11
# File 'lib/sunspot/query/pagination.rb', line 9

def per_page
  @per_page
end

Instance Method Details

#to_paramsObject



15
16
17
18
19
20
21
# File 'lib/sunspot/query/pagination.rb', line 15

def to_params
  if @cursor
    { :cursorMark => @cursor, :rows => rows }
  else
    { :start => start, :rows => rows }
  end
end