Module: HumanError::Error

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#codeObject

Returns the value of attribute code.



15
16
17
# File 'lib/human_error/error.rb', line 15

def code
  @code
end

#detailObject

Returns the value of attribute detail.



15
16
17
# File 'lib/human_error/error.rb', line 15

def detail
  @detail
end

#developer_documentation_urlObject

Returns the value of attribute developer_documentation_url.



15
16
17
# File 'lib/human_error/error.rb', line 15

def developer_documentation_url
  @developer_documentation_url
end

#external_documentation_urlObject

Returns the value of attribute external_documentation_url.



15
16
17
# File 'lib/human_error/error.rb', line 15

def external_documentation_url
  @external_documentation_url
end

#http_statusObject Also known as: status

Returns the value of attribute http_status.



15
16
17
# File 'lib/human_error/error.rb', line 15

def http_status
  @http_status
end

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/human_error/error.rb', line 15

def id
  @id
end

#messageObject

Returns the value of attribute message.



15
16
17
# File 'lib/human_error/error.rb', line 15

def message
  @message
end

#sourceObject

Returns the value of attribute source.



15
16
17
# File 'lib/human_error/error.rb', line 15

def source
  @source
end

#titleObject

Returns the value of attribute title.



15
16
17
# File 'lib/human_error/error.rb', line 15

def title
  @title
end

Class Method Details

.included(base) ⇒ Object



99
100
101
# File 'lib/human_error/error.rb', line 99

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/human_error/error.rb', line 31

def as_json(_options = {})
  {
    errors: [
      {
        id:     id,
        links:  {
          about:         external_documentation_url,
          documentation: developer_documentation_url,
        },
        status: http_status,
        code:   code,
        title:  title,
        detail: detail,
        source: source,
      },
    ],
  }
end

#initialize(**args) ⇒ Object



25
26
27
28
29
# File 'lib/human_error/error.rb', line 25

def initialize(**args)
  args.each do |variable, value|
    public_send("#{variable}=", value)
  end
end

#to_json(_options = {}) ⇒ Object



50
51
52
# File 'lib/human_error/error.rb', line 50

def to_json(_options = {})
  JSON.dump(as_json)
end

#to_sObject



95
96
97
# File 'lib/human_error/error.rb', line 95

def to_s
  @message || detail
end