Class: Skykick::RequestPagination::ODataPagination

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

Overview

Skykick uses Odata pagination but unfortunately does not support skipping pages. Using skip responds with “The query specified in the URI is not valid. Query option ‘Skip’ is not allowed. To allow it, set the ‘AllowedQueryOptions’ property on EnableQueryAttribute or QueryValidationSettings.”

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_size) ⇒ ODataPagination

Returns a new instance of ODataPagination.



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

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

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



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

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



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

def offset
  @offset
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

Class Method Details

.data(body) ⇒ Object



35
36
37
# File 'lib/skykick/pagination.rb', line 35

def self.data(body) 
  body
end

Instance Method Details

#more_pages?Boolean

only single page available

Returns:

  • (Boolean)


39
40
41
# File 'lib/skykick/pagination.rb', line 39

def more_pages?
  @offset == 0
end

#next_page!(data) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/skykick/pagination.rb', line 25

def next_page!(data)
  # assume array
  if data.count
    @total = data.count
  else
    @total = 1 
  end
  @offset += @limit
end

#page_optionsObject



21
22
23
24
# File 'lib/skykick/pagination.rb', line 21

def page_options
  { '$top': @limit, '$skip': @offset }
  { '$top': @limit }
end