Class: JSONAPI::Request::QueryParamCollection::PageParam

Inherits:
QueryParam show all
Defined in:
lib/easy/jsonapi/request/query_param_collection/page_param.rb

Overview

Used to create a unique Page JSONAPI::Request::QueryParamCollection::QueryParam

Instance Attribute Summary

Attributes inherited from Item

#item

Instance Method Summary collapse

Methods inherited from QueryParam

#name=

Methods inherited from NameValuePair

#name, #name=, #to_h

Methods inherited from Item

#to_h

Constructor Details

#initialize(offset:, limit:) ⇒ PageParam

Returns a new instance of PageParam.

Parameters:

  • offset (Integer | String)

    the page offset

  • limit (Integer | String)

    the # of resources returned on a given page



13
14
15
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 13

def initialize(offset:, limit:)
  super('page', { offset: offset.to_i, limit: limit.to_i })
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JSONAPI::Item

Instance Method Details

#limitInteger

Returns The # of resources returned on a given page.

Returns:

  • (Integer)

    The # of resources returned on a given page



38
39
40
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 38

def limit
  @item[:value][:limit]
end

#limit=(new_limit) ⇒ Object

Parameters:

  • new_limit (Integer)

    The new page limit number



43
44
45
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 43

def limit=(new_limit)
  @item[:value][:limit] = new_limit.to_i
end

#offsetInteger

Returns The page offset.

Returns:

  • (Integer)

    The page offset



28
29
30
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 28

def offset
  @item[:value][:offset]
end

#offset=(new_offset) ⇒ Object

Parameters:

  • new_offset (Integer | String)

    The new page offset number



33
34
35
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 33

def offset=(new_offset)
  @item[:value][:offset] = new_offset.to_i
end

#to_sObject

Represents the Page class in a string format



48
49
50
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 48

def to_s
  "page[offset]=#{offset}&page[limit]=#{limit}"
end

#valueObject

Raises:

  • (RuntimeError)

    Informs user to use a different method



18
19
20
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 18

def value
  raise 'PageParam does not provide a #value method, try #offset or #limit instead'
end

#value=(_) ⇒ Object

Raises:

  • (RuntimeError)

    Informs user to use a different method



23
24
25
# File 'lib/easy/jsonapi/request/query_param_collection/page_param.rb', line 23

def value=(_)
  raise 'PageParam does not provide a #value= method, try #offset= or #limit= instead'
end