Class: Lutaml::Xsd::Errors::ErrorContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/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

  • :repository (Lutaml::Xsd::SchemaRepository)

    Schema repository



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lutaml/xsd/errors/error_context.rb', line 42

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

Instance Attribute Details

#actual_valueString? (readonly)

Returns Actual value that caused the error.

Returns:

  • (String, nil)

    Actual value that caused the error



26
27
28
# File 'lib/lutaml/xsd/errors/error_context.rb', line 26

def actual_value
  @actual_value
end

#additionalHash (readonly)

Returns Additional context attributes.

Returns:

  • (Hash)

    Additional context attributes



32
33
34
# File 'lib/lutaml/xsd/errors/error_context.rb', line 32

def additional
  @additional
end

#expected_typeString? (readonly)

Returns Expected type name.

Returns:

  • (String, nil)

    Expected type name



23
24
25
# File 'lib/lutaml/xsd/errors/error_context.rb', line 23

def expected_type
  @expected_type
end

#locationString? (readonly)

Returns XPath location of the error.

Returns:

  • (String, nil)

    XPath location of the error



17
18
19
# File 'lib/lutaml/xsd/errors/error_context.rb', line 17

def location
  @location
end

#namespaceString? (readonly)

Returns Namespace URI.

Returns:

  • (String, nil)

    Namespace URI



20
21
22
# File 'lib/lutaml/xsd/errors/error_context.rb', line 20

def namespace
  @namespace
end

#repositoryLutaml::Xsd::SchemaRepository? (readonly)

Returns Schema repository for suggestions.

Returns:



29
30
31
# File 'lib/lutaml/xsd/errors/error_context.rb', line 29

def repository
  @repository
end

Instance Method Details

#has_repository?Boolean

Check if context has repository for suggestions

Returns:

  • (Boolean)

    True if repository is available



69
70
71
# File 'lib/lutaml/xsd/errors/error_context.rb', line 69

def has_repository?
  !@repository.nil?
end

#to_hHash

Convert context to hash representation

Returns:

  • (Hash)

    Context as hash



57
58
59
60
61
62
63
64
# File 'lib/lutaml/xsd/errors/error_context.rb', line 57

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