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.



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

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.



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

def errors
  @errors
end

#exceptionObject (readonly)

Returns the value of attribute exception.



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

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).



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

attr_reader :errors, :exception

#r exception(exception) ⇒ Object

The exception that caused the error. Defaults to nil.



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

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.



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

def success?
  false
end