Class: Lutaml::Xml::Schema::Xsd::Errors::ErrorContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/schema/xsd/errors/error_context.rb

Overview

Value object representing contextual information for enhanced errors

Examples:

Creating an error context

context = ErrorContext.new(
  location: "/root/element[1]",
  namespace: "http://example.com",
  expected_type: "xs:string",
  actual_value: "123"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ ErrorContext

Initialize error context with attributes

Parameters:

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

    Context attributes

Options Hash (attrs):

  • :location (String)

    XPath location

  • :namespace (String)

    Namespace URI

  • :expected_type (String)

    Expected type name

  • :actual_value (String)

    Actual value



40
41
42
43
44
45
46
47
48
49
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 40

def initialize(attrs = {})
  @location = attrs[:location]
  @namespace = attrs[:namespace]
  @expected_type = attrs[:expected_type]
  @actual_value = attrs[:actual_value]
  @additional = attrs.except(
    :location, :namespace, :expected_type,
    :actual_value
  )
end

Instance Attribute Details

#actual_valueString? (readonly)

Returns Actual value that caused the error.

Returns:

  • (String, nil)

    Actual value that caused the error



28
29
30
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 28

def actual_value
  @actual_value
end

#additionalHash (readonly)

Returns Additional context attributes.

Returns:

  • (Hash)

    Additional context attributes



31
32
33
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 31

def additional
  @additional
end

#expected_typeString? (readonly)

Returns Expected type name.

Returns:

  • (String, nil)

    Expected type name



25
26
27
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 25

def expected_type
  @expected_type
end

#locationString? (readonly)

Returns XPath location of the error.

Returns:

  • (String, nil)

    XPath location of the error



19
20
21
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 19

def location
  @location
end

#namespaceString? (readonly)

Returns Namespace URI.

Returns:

  • (String, nil)

    Namespace URI



22
23
24
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 22

def namespace
  @namespace
end

Instance Method Details

#to_hHash

Convert context to hash representation

Returns:

  • (Hash)

    Context as hash



54
55
56
57
58
59
60
61
# File 'lib/lutaml/xml/schema/xsd/errors/error_context.rb', line 54

def to_h
  {
    location: @location,
    namespace: @namespace,
    expected_type: @expected_type,
    actual_value: @actual_value,
  }.merge(@additional).compact
end