Class: JSONAPI::Field

Inherits:
Item
  • Object
show all
Defined in:
lib/easy/jsonapi/field.rb

Overview

Field is the name of key value pair

Instance Attribute Summary

Attributes inherited from Item

#item

Instance Method Summary collapse

Methods inherited from Item

#to_h

Constructor Details

#initialize(name, type: String) ⇒ Field

Returns a new instance of Field.

Parameters:

  • name (String)

    The name of the field

  • type (String | nil) (defaults to: String)

    The type of the field



11
12
13
# File 'lib/easy/jsonapi/field.rb', line 11

def initialize(name, type: String)
  super({ name: name.to_s, type: type })
end

Dynamic Method Handling

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

Instance Method Details

#nameString

Returns The Field’s name.

Returns:

  • (String)

    The Field’s name



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

def name
  @item[:name]
end

#name=(_) ⇒ Object

Raises:

  • RunTimeError You shoulddn’t be able to update the name of a Resource::Field



22
23
24
# File 'lib/easy/jsonapi/field.rb', line 22

def name=(_)
  raise 'Cannot change the name of a Resource::Field'
end

#to_sString

Returns The name of the field.

Returns:

  • (String)

    The name of the field.



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

def to_s
  name
end

#typeObject

Returns The type of the field.

Returns:

  • (Object)

    The type of the field



27
28
29
# File 'lib/easy/jsonapi/field.rb', line 27

def type
  @item[:type]
end

#type=(new_type) ⇒ Object

Parameters:

  • new_type (Object)

    The new type of field.



32
33
34
# File 'lib/easy/jsonapi/field.rb', line 32

def type=(new_type)
  @item[:type] = new_type
end