Class: Lutaml::Xsd::ValidationError

Inherits:
Model::Serializable
  • Object
show all
Defined in:
lib/lutaml/xsd/validation_error.rb

Overview

Represents a single validation error with structured information

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(field:, message:, value: nil, constraint: nil) ⇒ ValidationError

Factory method for creating validation errors with type conversion

Parameters:

  • field (Symbol, String)

    The field that failed validation

  • message (String)

    Human-readable error message

  • value (Object) (defaults to: nil)

    The actual value that was invalid (optional)

  • constraint (String) (defaults to: nil)

    The constraint that was violated (optional)

Returns:



25
26
27
28
29
30
31
32
# File 'lib/lutaml/xsd/validation_error.rb', line 25

def self.create(field:, message:, value: nil, constraint: nil)
  new(
    field: field.to_s,
    message: message,
    value: value&.to_s,
    constraint: constraint,
  )
end

Instance Method Details

#to_sString

Format as human-readable string

Returns:

  • (String)


36
37
38
39
40
41
# File 'lib/lutaml/xsd/validation_error.rb', line 36

def to_s
  parts = ["#{field}: #{message}"]
  parts << "(value: #{value})" if value
  parts << "[constraint: #{constraint}]" if constraint
  parts.join(" ")
end