Class: JSONAPI::Request::QueryParamCollection::FieldsParam::Fieldset

Inherits:
Object
  • Object
show all
Defined in:
lib/easy/jsonapi/request/query_param_collection/fields_param/fieldset.rb

Overview

Collection of fields related to specific resource objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_type, field_arr = []) ⇒ Fieldset

Returns a new instance of Fieldset.

Parameters:

  • field_arr (Array<JSONAPI::Field>) (defaults to: [])

    A fieldset is a collection of Resource Fields



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

def initialize(resource_type, field_arr = [])
  @resource_type = resource_type
  @fields = field_arr
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



14
15
16
# File 'lib/easy/jsonapi/request/query_param_collection/fields_param/fieldset.rb', line 14

def fields
  @fields
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



14
15
16
# File 'lib/easy/jsonapi/request/query_param_collection/fields_param/fieldset.rb', line 14

def resource_type
  @resource_type
end

Instance Method Details

#to_sObject

Represention of Fieldset as a string where fields

are comma separated strings


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

def to_s
  pre_string = "fields[#{@resource_type}]="
  JSONAPI::Utility.to_string_collection(@fields, delimiter: ',', pre_string: pre_string)
end