Exception: Validate::Error::ConstraintViolationError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/validate/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(violations) ⇒ ConstraintViolationError

Returns a new instance of ConstraintViolationError.



27
28
29
30
# File 'lib/validate/errors.rb', line 27

def initialize(violations)
  @violations = violations
  super()
end

Instance Attribute Details

#violationsObject (readonly)

Returns the value of attribute violations.



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

def violations
  @violations
end

Instance Method Details

#messageObject



32
33
34
35
36
37
# File 'lib/validate/errors.rb', line 32

def message
  @violations.group_by(&:path)
             .transform_values { |violations| violations.map(&:message) }
             .map { |path, messages| "#{path}: #{messages.join(', ')}" }
             .join("\n")
end