Class: JsonApiClient::RequestParams
- Inherits:
-
Object
- Object
- JsonApiClient::RequestParams
- Defined in:
- lib/json_api_client/request_params.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #add_includes(includes) ⇒ Object
- #clear ⇒ Object
- #field_types ⇒ Object
-
#initialize(klass, includes: [], fields: {}) ⇒ RequestParams
constructor
A new instance of RequestParams.
- #remove_fields(type) ⇒ Object
- #reset_includes! ⇒ Object
- #set_fields(type, field_names) ⇒ Object
- #to_params ⇒ Object
Constructor Details
#initialize(klass, includes: [], fields: {}) ⇒ RequestParams
Returns a new instance of RequestParams.
5 6 7 8 9 |
# File 'lib/json_api_client/request_params.rb', line 5 def initialize(klass, includes: [], fields: {}) @klass = klass @includes = includes @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
3 4 5 |
# File 'lib/json_api_client/request_params.rb', line 3 def fields @fields end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
3 4 5 |
# File 'lib/json_api_client/request_params.rb', line 3 def includes @includes end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
3 4 5 |
# File 'lib/json_api_client/request_params.rb', line 3 def klass @klass end |
Instance Method Details
#add_includes(includes) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/json_api_client/request_params.rb', line 11 def add_includes(includes) Utils.parse_includes(klass, *includes).each do |name| name = name.to_sym self.includes.push(name) unless self.includes.include?(name) end end |
#clear ⇒ Object
34 35 36 37 |
# File 'lib/json_api_client/request_params.rb', line 34 def clear reset_includes! @fields = {} end |
#field_types ⇒ Object
30 31 32 |
# File 'lib/json_api_client/request_params.rb', line 30 def field_types self.fields.keys end |
#remove_fields(type) ⇒ Object
26 27 28 |
# File 'lib/json_api_client/request_params.rb', line 26 def remove_fields(type) self.fields.delete(type.to_sym) end |
#reset_includes! ⇒ Object
18 19 20 |
# File 'lib/json_api_client/request_params.rb', line 18 def reset_includes! @includes = [] end |
#set_fields(type, field_names) ⇒ Object
22 23 24 |
# File 'lib/json_api_client/request_params.rb', line 22 def set_fields(type, field_names) self.fields[type.to_sym] = field_names.map(&:to_sym) end |
#to_params ⇒ Object
39 40 41 42 |
# File 'lib/json_api_client/request_params.rb', line 39 def to_params return nil if field_types.empty? && includes.empty? parsed_fields.merge(parsed_includes) end |