Class: JSONAPI::Request::QueryParamCollection::QueryParam

Inherits:
NameValuePair show all
Defined in:
lib/easy/jsonapi/request/query_param_collection/query_param.rb

Overview

A generic name=value query parameter

Instance Attribute Summary

Attributes inherited from Item

#item

Instance Method Summary collapse

Methods inherited from NameValuePair

#name, #to_h, #value

Methods inherited from Item

#to_h

Constructor Details

#initialize(name, value) ⇒ QueryParam

Returns a new instance of QueryParam.

Parameters:

  • name (String)

    The name of the parameter

  • value (String | Array<String>)

    The value of the parameter



17
18
19
20
21
22
23
# File 'lib/easy/jsonapi/request/query_param_collection/query_param.rb', line 17

def initialize(name, value)
  if instance_of?(QueryParam)
    JSONAPI::Exceptions::QueryParamsExceptions.check_param_name(name)
  end
  value = value.split(',') if value.is_a? String
  super(name, value)
end

Dynamic Method Handling

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

Instance Method Details

#name=(_) ⇒ Object

Raises:

  • RuntimeError Cannot change the name of a QueryParam object



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

def name=(_)
  raise 'Cannot change the name of QueryParam Objects'
end

#to_sObject

Represents a parameter as a string



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

def to_s
  "#{name}=#{JSONAPI::Utility.to_string_collection(value, delimiter: ',')}"
end

#value=(new_value) ⇒ Object

Update the query_param value, turning value into an array if it was given as a string

Parameters:

  • new_value (String, Array<String>)

    The new value of the Parameter



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

def value=(new_value)
  new_value = new_value.split(',') if new_value.is_a? String
  super(new_value)
end