Class: JSONAPI::Request::QueryParamCollection

Inherits:
NameValuePairCollection show all
Defined in:
lib/easy/jsonapi/request/query_param_collection.rb,
lib/easy/jsonapi/request/query_param_collection/page_param.rb,
lib/easy/jsonapi/request/query_param_collection/sort_param.rb,
lib/easy/jsonapi/request/query_param_collection/query_param.rb,
lib/easy/jsonapi/request/query_param_collection/fields_param.rb,
lib/easy/jsonapi/request/query_param_collection/filter_param.rb,
lib/easy/jsonapi/request/query_param_collection/include_param.rb,
lib/easy/jsonapi/request/query_param_collection/filter_param/filter.rb,
lib/easy/jsonapi/request/query_param_collection/fields_param/fieldset.rb

Overview

A collection of QueryParam objects

Defined Under Namespace

Classes: FieldsParam, FilterParam, IncludeParam, PageParam, QueryParam, SortParam

Constant Summary collapse

SPECIAL_QUERY_PARAMS =

The special query params defined by the JSON:API specification

%i[sorts filters fields page includes].freeze

Instance Method Summary collapse

Methods inherited from NameValuePairCollection

#<<, #to_h

Methods inherited from Collection

#[], #[]=, #each, #empty?, #get, #include?, #insert, #keys, #remove, #set, #size

Constructor Details

#initialize(param_arr = []) ⇒ QueryParamCollection

Returns a new instance of QueryParamCollection.

Parameters:



16
17
18
# File 'lib/easy/jsonapi/request/query_param_collection.rb', line 16

def initialize(param_arr = [])
  super(param_arr, item_type: JSONAPI::Request::QueryParamCollection::QueryParam)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

Gets the QueryParam object whose name matches the method_name called

Parameters:

  • method_name (Symbol)

    The name of the method called

  • args

    If any arguments were passed to the method called

  • block

    If a block was passed to the method called



47
48
49
50
51
52
53
54
# File 'lib/easy/jsonapi/request/query_param_collection.rb', line 47

def method_missing(method_name, *args, &block)
  included = include?(method_name)
  super unless included || SPECIAL_QUERY_PARAMS.include?(method_name)
  if included
    return get(method_name)
  end
  nil
end

Instance Method Details

#add(param) ⇒ Object

Add a QueryParameter to the collection. (CASE-SENSITIVE)

Parameters:



25
26
27
# File 'lib/easy/jsonapi/request/query_param_collection.rb', line 25

def add(param)
  super(param, &:name)
end

#to_sObject

Represent query param collection like the query_param string



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

def to_s
  JSONAPI::Utility.to_string_collection(self, delimiter: '&')
end