Class: WrAPI::RequestPagination::DefaultPager

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

Overview

DefaultPager handles pagination by assuming all data is retrieved in a single go.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_page_size = nil) ⇒ DefaultPager

Initializes the pager with an optional page size.

Parameters:

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

    the size of the page (not used in this implementation)



14
15
16
# File 'lib/wrapi/pagination.rb', line 14

def initialize(_page_size = nil)
  @page = 0
end

Class Method Details

.data(body) ⇒ Object

Processes the data from the response body.

Parameters:

  • body (Object)

    the response body

Returns:

  • (Object)

    the processed data (in this case, the body itself)



45
46
47
# File 'lib/wrapi/pagination.rb', line 45

def self.data(body)
  body
end

Instance Method Details

#more_pages?Boolean

Checks if there are more pages.

Returns:

  • (Boolean)

    true if there are more pages, false otherwise



30
31
32
# File 'lib/wrapi/pagination.rb', line 30

def more_pages?
  @page < 1
end

#next_page!(_data = nil) ⇒ Boolean

Advances to the next page.

Parameters:

  • _data (Object, nil) (defaults to: nil)

    the data from the current page (not used in this implementation)

Returns:

  • (Boolean)

    true if there are more pages, false otherwise



22
23
24
25
# File 'lib/wrapi/pagination.rb', line 22

def next_page!(_data = nil)
  @page += 1
  more_pages?
end

#page_optionsHash

Returns options for the current page to add to get request.

Returns:

  • (Hash)

    an empty hash as options



37
38
39
# File 'lib/wrapi/pagination.rb', line 37

def page_options
  {}
end