Class: JSONAPI::Document::Error

Inherits:
NameValuePairCollection show all
Defined in:
lib/easy/jsonapi/document/error.rb,
lib/easy/jsonapi/document/error/error_member.rb

Overview

An individual errors member in a jsonapi’s document top level ‘errors’ member array

Defined Under Namespace

Classes: ErrorMember

Instance Method Summary collapse

Methods inherited from NameValuePairCollection

#to_s

Methods inherited from Collection

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

Constructor Details

#initialize(err_members = []) ⇒ Error

Returns a new instance of Error.

Parameters:



14
15
16
# File 'lib/easy/jsonapi/document/error.rb', line 14

def initialize(err_members = [])
  super(err_members, item_type: JSONAPI::Document::Error::ErrorMember)
end

Dynamic Method Handling

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

Instance Method Details

#<<(error_mem) ⇒ Object

Another way to call add

Parameters:



29
30
31
# File 'lib/easy/jsonapi/document/error.rb', line 29

def <<(error_mem)
  super(error_mem, &:name)
end

#add(error_mem) ⇒ Object

Add a error to the collection using it’s name

Parameters:



23
24
25
# File 'lib/easy/jsonapi/document/error.rb', line 23

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

#to_hObject

Represent an Error as a hash



42
43
44
# File 'lib/easy/jsonapi/document/error.rb', line 42

def to_h
  JSONAPI::Utility.to_h_collection(self)
end