Class: SiteSearch::Query::Pagination

Inherits:
Data
  • Object
show all
Defined in:
app/services/site_search/query.rb

Overview

next_page is what drives infinite scroll — nil means the end, so the
client never has to guess whether one more request is worth making.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page: 1, next_page: nil, pages: 1, count: 0) ⇒ Pagination

Returns a new instance of Pagination.

Parameters:

  • page (Integer) (defaults to: 1)

    the page just served

  • next_page (Integer, nil) (defaults to: nil)

    nil at the end of the results

  • pages (Integer) (defaults to: 1)

    how deep the results go

  • count (Integer) (defaults to: 0)

    total matches across every engine



35
# File 'app/services/site_search/query.rb', line 35

def initialize(page: 1, next_page: nil, pages: 1, count: 0) = super

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



30
31
32
# File 'app/services/site_search/query.rb', line 30

def count
  @count
end

#next_pageObject (readonly)

Returns the value of attribute next_page

Returns:

  • (Object)

    the current value of next_page



30
31
32
# File 'app/services/site_search/query.rb', line 30

def next_page
  @next_page
end

#pageObject (readonly)

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page



30
31
32
# File 'app/services/site_search/query.rb', line 30

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages

Returns:

  • (Object)

    the current value of pages



30
31
32
# File 'app/services/site_search/query.rb', line 30

def pages
  @pages
end

Instance Method Details

#as_jsonHash

Returns the pagination block as the browser consumes it.

Returns:

  • (Hash)

    the pagination block as the browser consumes it



38
# File 'app/services/site_search/query.rb', line 38

def as_json(*) = { page:, next: next_page, pages:, count: }