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”



34
35
36
37
38
# File 'lib/gruf/errors/field.rb', line 34

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

Instance Attribute Details

#error_codeSymbol (readonly)

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

Returns:

  • (Symbol)

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



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

def error_code
  @error_code
end

#field_nameSymbol (readonly)

Returns The name of the field as a Symbol.

Returns:

  • (Symbol)

    The name of the field as a Symbol



23
24
25
# File 'lib/gruf/errors/field.rb', line 23

def field_name
  @field_name
end

#messageString (readonly)

Returns The error message for the field, e.g. “Job with ID 123 not found”.

Returns:

  • (String)

    The error message for the field, e.g. “Job with ID 123 not found”



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

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



45
46
47
48
49
50
51
# File 'lib/gruf/errors/field.rb', line 45

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