class Cuprum::Collections::Errors::FailedValidation
Error returned when a collection item fails validation.
Constants
- COMPARABLE_PROPERTIES
- TYPE
Short string used to identify the type of error.
Attributes
entity_class[R]
@return [Class] the class of the assigned entity.
errors[R]
@return [Stannum::Errors] The errors generated when validating the entity.
Public Class Methods
new(entity_class:, errors:)
click to toggle source
@param entity_class
[Class] The class of the assigned entity. @param errors [Stannum::Errors] The errors generated when validating the
entity.
Calls superclass method
# File lib/cuprum/collections/errors/failed_validation.rb, line 19 def initialize(entity_class:, errors:) @entity_class = entity_class @errors = errors super( entity_class: entity_class, errors: errors, message: default_message ) end
Public Instance Methods
as_json()
click to toggle source
@return [Hash] a serializable hash representation of the error.
# File lib/cuprum/collections/errors/failed_validation.rb, line 37 def as_json { 'data' => { 'entity_class' => entity_class.name, 'errors' => format_errors }, 'message' => message, 'type' => type } end
type()
click to toggle source
@return [String] short string used to identify the type of error.
# File lib/cuprum/collections/errors/failed_validation.rb, line 49 def type TYPE end
Private Instance Methods
default_message()
click to toggle source
# File lib/cuprum/collections/errors/failed_validation.rb, line 55 def default_message "#{entity_class.name} failed validation" end
format_errors()
click to toggle source
# File lib/cuprum/collections/errors/failed_validation.rb, line 59 def format_errors errors .with_messages .group_by_path { |err| err[:message] } .transform_keys { |path| path.map(&:to_s).join('.') } end