Class: Gruf::Errors::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/errors/field.rb

Overview

Represents a field-specific error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field_name, error_code, message = '') ⇒ Field

Returns a new instance of Field.

Parameters:

  • field_name (Symbol)

    The name of the field as a Symbol

  • error_code (Symbol)

    The application error code for the field, e.g. :job_not_found

  • message (String) (defaults to: '')

    (Optional) The error message for the field, e.g. "Job with ID 123 not found"



39
40
41
42
43
# File 'lib/gruf/errors/field.rb', line 39

def initialize(field_name, error_code, message = '')
  @field_name = field_name
  @error_code = error_code
  @message = message
end

Instance Attribute Details

#error_codeObject (readonly)

Returns the value of attribute error_code.



29
30
31
# File 'lib/gruf/errors/field.rb', line 29

def error_code
  @error_code
end

#field_nameObject (readonly)

Returns the value of attribute field_name.



26
27
28
# File 'lib/gruf/errors/field.rb', line 26

def field_name
  @field_name
end

#messageObject (readonly)

Returns the value of attribute message.



32
33
34
# File 'lib/gruf/errors/field.rb', line 32

def message
  @message
end

Instance Method Details

#to_hHash

Return the field error represented as a hash

Returns:

  • (Hash)

    The error represented as a hash



50
51
52
53
54
55
56
# File 'lib/gruf/errors/field.rb', line 50

def to_h
  {
    field_name: field_name,
    error_code: error_code,
    message: message
  }
end