Class: ClientErrorDetail

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperion/types/client_error_detail.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, resource, opts = {}) ⇒ ClientErrorDetail

Returns a new instance of ClientErrorDetail.



10
11
12
13
14
15
16
# File 'lib/hyperion/types/client_error_detail.rb', line 10

def initialize(code, resource, opts={})
  @code = canonical_code(code)
  @resource = resource
  @field = opts[:field] || ''
  @value = opts[:value] || ''
  @reason = opts[:reason] || ''
end

Instance Attribute Details

#codeObject (readonly)

ClientErrorCode

type of error



4
5
6
# File 'lib/hyperion/types/client_error_detail.rb', line 4

def code
  @code
end

#fieldObject (readonly)

String, Nil

the location of the error within the resource



6
7
8
# File 'lib/hyperion/types/client_error_detail.rb', line 6

def field
  @field
end

#reasonObject (readonly)

Object, Nil

an explanation of the error. usually a String.



8
9
10
# File 'lib/hyperion/types/client_error_detail.rb', line 8

def reason
  @reason
end

#resourceObject (readonly)

String

the thing with the error



5
6
7
# File 'lib/hyperion/types/client_error_detail.rb', line 5

def resource
  @resource
end

#valueObject (readonly)

Object, Nil

the problematic data



7
8
9
# File 'lib/hyperion/types/client_error_detail.rb', line 7

def value
  @value
end

Class Method Details

.from_attrs(attrs) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/hyperion/types/client_error_detail.rb', line 28

def self.from_attrs(attrs)
  code = ClientErrorCode.from(attrs['code'])
  resource = attrs['resource']
  field = attrs['field']
  value = attrs['value']
  reason = attrs['reason']
  self.new(code, resource, field: field, value: value, reason: reason)
end

Instance Method Details

#as_jsonObject



18
19
20
21
22
23
24
25
26
# File 'lib/hyperion/types/client_error_detail.rb', line 18

def as_json
  {
      'code' => code.value,
      'resource' => resource,
      'field' => field,
      'value' => value,
      'reason' => reason
  }
end

#empty?Boolean

Returns:

  • (Boolean)


39
# File 'lib/hyperion/types/client_error_detail.rb', line 39

def empty?; false; end

#to_sObject

make mongoid validations happy



38
# File 'lib/hyperion/types/client_error_detail.rb', line 38

def to_s; reason; end