Class: Lutaml::Qea::Validation::ValidationMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/qea/validation/validation_message.rb

Overview

Represents a single validation message with severity, category, and context information

Examples:

Creating an error message

message = ValidationMessage.new(
  severity: :error,
  category: :missing_reference,
  entity_type: :association,
  entity_id: "FA86EB3B-198A-4141-83F6-DE9FACC76425",
  entity_name: "Association_1",
  field: "member_end",
  reference: "GPLR_Compression",
  message: "member_end references non-existent class",
  location: "Package::SubPackage"
)

Defined Under Namespace

Modules: Category, Severity

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(severity:, category:, entity_type:, entity_id:, entity_name:, message:, field: nil, reference: nil, location: nil, context: {}) ⇒ ValidationMessage

Creates a new validation message

Parameters:

  • severity (Symbol)

    Message severity (:error, :warning, :info)

  • category (Symbol)

    Category of the issue

  • entity_type (Symbol)

    Type of entity (e.g., :class, :association)

  • entity_id (String)

    XMI ID or database ID of the entity

  • entity_name (String)

    Human-readable name of the entity

  • field (String, nil) (defaults to: nil)

    Field with the issue

  • reference (String, nil) (defaults to: nil)

    What it’s trying to reference

  • message (String)

    Human-readable description

  • location (String, nil) (defaults to: nil)

    Package path or context

  • context (Hash) (defaults to: {})

    Additional context information



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/lutaml/qea/validation/validation_message.rb', line 57

def initialize( # rubocop:disable Metrics/ParameterLists
  severity:,
  category:,
  entity_type:,
  entity_id:,
  entity_name:,
  message:,
  field: nil,
  reference: nil,
  location: nil,
  context: {}
)
  @severity = severity
  @category = category
  @entity_type = entity_type
  @entity_id = entity_id
  @entity_name = entity_name
  @field = field
  @reference = reference
  @message = message
  @location = location
  @context = context
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def category
  @category
end

#contextObject (readonly)

Returns the value of attribute context.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def context
  @context
end

#entity_idObject (readonly)

Returns the value of attribute entity_id.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def entity_id
  @entity_id
end

#entity_nameObject (readonly)

Returns the value of attribute entity_name.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def entity_name
  @entity_name
end

#entity_typeObject (readonly)

Returns the value of attribute entity_type.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def entity_type
  @entity_type
end

#fieldObject (readonly)

Returns the value of attribute field.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def field
  @field
end

#locationObject (readonly)

Returns the value of attribute location.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def message
  @message
end

#referenceObject (readonly)

Returns the value of attribute reference.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def reference
  @reference
end

#severityObject (readonly)

Returns the value of attribute severity.



40
41
42
# File 'lib/lutaml/qea/validation/validation_message.rb', line 40

def severity
  @severity
end

Instance Method Details

#error?Boolean

Checks if this is an error message

Returns:

  • (Boolean)


84
85
86
# File 'lib/lutaml/qea/validation/validation_message.rb', line 84

def error?
  severity == Severity::ERROR
end

#info?Boolean

Checks if this is an info message

Returns:

  • (Boolean)


98
99
100
# File 'lib/lutaml/qea/validation/validation_message.rb', line 98

def info?
  severity == Severity::INFO
end

#to_hHash

Returns a hash representation of the message

Returns:

  • (Hash)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/lutaml/qea/validation/validation_message.rb', line 119

def to_h # rubocop:disable Metrics/MethodLength
  {
    severity: severity,
    category: category,
    entity_type: entity_type,
    entity_id: entity_id,
    entity_name: entity_name,
    field: field,
    reference: reference,
    message: message,
    location: location,
    context: context,
  }.compact
end

#to_json(*args) ⇒ String

Returns a JSON representation of the message

Returns:

  • (String)


137
138
139
140
# File 'lib/lutaml/qea/validation/validation_message.rb', line 137

def to_json(*args)
  require "json"
  to_h.to_json(*args)
end

#to_sString

Returns a formatted string representation of the message

Returns:

  • (String)


105
106
107
108
109
110
111
112
113
114
# File 'lib/lutaml/qea/validation/validation_message.rb', line 105

def to_s # rubocop:disable Metrics/AbcSize
  parts = []
  parts << "#{entity_type.to_s.capitalize} '#{entity_name}'"
  parts << "{#{entity_id}}"
  parts << "└─ #{message}"
  parts << "└─ Field: #{field}" if field
  parts << "└─ Reference: #{reference}" if reference
  parts << "└─ Location: #{location}" if location
  parts.join("\n")
end

#warning?Boolean

Checks if this is a warning message

Returns:

  • (Boolean)


91
92
93
# File 'lib/lutaml/qea/validation/validation_message.rb', line 91

def warning?
  severity == Severity::WARNING
end