Class: Veeam::RequestPagination::PagingInfoPager

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_size) ⇒ PagingInfoPager

Returns a new instance of PagingInfoPager.



11
12
13
14
15
16
# File 'lib/veeam/pagination.rb', line 11

def initialize(page_size)
  @offset = 0
  @limit = page_size
  # we halways have a first page
  @total = @offset + 1
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



10
11
12
# File 'lib/veeam/pagination.rb', line 10

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



10
11
12
# File 'lib/veeam/pagination.rb', line 10

def offset
  @offset
end

#totalObject (readonly)

Returns the value of attribute total.



10
11
12
# File 'lib/veeam/pagination.rb', line 10

def total
  @total
end

Class Method Details

.data(body) ⇒ Object



36
37
38
# File 'lib/veeam/pagination.rb', line 36

def self.data(body) 
  body['data'] ? body['data'] : body
end

Instance Method Details

#more_pages?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/veeam/pagination.rb', line 28

def more_pages?
  @offset < @total
end

#next_page!(data) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/veeam/pagination.rb', line 20

def next_page!(data)
  @offset += @limit
  meta = page_info(data)
  if meta
    @total = meta['total'].to_i 
  end
end

#page_info(body) ⇒ Object



32
33
34
# File 'lib/veeam/pagination.rb', line 32

def page_info(body) 
  body['meta']['pagingInfo'] if body['meta'] && body['meta']['pagingInfo'] 
end

#page_optionsObject



17
18
19
# File 'lib/veeam/pagination.rb', line 17

def page_options
  { limit: @limit, offset: @offset }
end