Class: Modulorails::ErrorData

Inherits:
Object
  • Object
show all
Defined in:
lib/modulorails/error_data.rb

Overview

An error encountered during an operation with additional data.

Author:

  • Matthieu Ciappara <ciappa_m@modulotech>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors, exception: nil) ⇒ ErrorData

Returns a new instance of ErrorData.

Parameters:

  • errors (String, Array<String>)

    An error message or an array of error messages

  • exception (Exception, nil) (defaults to: nil)

    The exception that caused the error.



13
14
15
16
# File 'lib/modulorails/error_data.rb', line 13

def initialize(errors, exception: nil)
  @errors    = errors.respond_to?(:join) ? errors.join(', ') : errors.to_s
  @exception = exception
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/modulorails/error_data.rb', line 9

def errors
  @errors
end

#exceptionObject (readonly)

Returns the value of attribute exception.



9
10
11
# File 'lib/modulorails/error_data.rb', line 9

def exception
  @exception
end

#r errors(errors) ⇒ Object

An error message or an array of error messages (those will be joined by a coma and a space).



9
# File 'lib/modulorails/error_data.rb', line 9

attr_reader :errors, :exception

#r exception(exception) ⇒ Object

The exception that caused the error. Defaults to nil.



9
# File 'lib/modulorails/error_data.rb', line 9

attr_reader :errors, :exception

Instance Method Details

#success?false

Returns An error always means the operation was not a success.

Returns:

  • (false)

    An error always means the operation was not a success.



19
20
21
# File 'lib/modulorails/error_data.rb', line 19

def success?
  false
end