Class: Lutaml::Xml::Schema::Xsd::NamespaceUriRemapping

Inherits:
Model::Serializable show all
Defined in:
lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb

Overview

Namespace URI remapping rule (URI → URI transformation)

Constant Summary

Constants included from Model::Serialize

Model::Serialize::DEFAULT_VALUE_MAP, Model::Serialize::INTERNAL_ATTRIBUTES, Model::Serialize::LAZY_EMPTY_COLLECTION

Instance Attribute Summary

Attributes included from Model::Serialize

#lutaml_parent, #lutaml_register, #lutaml_root

Instance Method Summary collapse

Methods included from Model::Serialize

#attr_value, #attribute_exist?, #extract_register_id, included, #init_deserialization_state, #initialize, #key_exist?, #key_value, #method_missing, #prepare_instance_format_options, #pretty_print_instance_variables, register_format_mapping_method, register_from_format_method, register_to_format_method, #respond_to_missing?, #to_format, #to_yaml_hash, #using_default?, #using_default_for, #validate_attribute!, #validate_root_mapping!, #value_map, #value_set_for

Methods included from Model::Liquefiable

included, #to_liquid

Methods included from Model::Validation

#format_element_sequences, #order_names, #validate_helper, #validate_sequence!

Methods included from Model::ComparableModel

#already_compared?, #attributes_hash, #calculate_hash, #comparison_key, #eql?, #hash, included, #same_class?

Methods included from Model::Serialize::Builder

#initialize, #mixed_content?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lutaml::Model::Serialize

Instance Method Details

#apply(uri) ⇒ String

Apply remapping to a URI

Parameters:

  • uri (String)

    Namespace URI

Returns:

  • (String)

    Remapped URI or original



72
73
74
# File 'lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb', line 72

def apply(uri)
  uri == from_uri ? to_uri : uri
end

#valid?Boolean

Check if remapping is valid

Returns:

  • (Boolean)


59
60
61
# File 'lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb', line 59

def valid?
  validate.valid?
end

#validateValidationResult

Validate remapping

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb', line 22

def validate
  errors = []

  from_missing = from_uri.nil? || from_uri.empty?
  to_missing = to_uri.nil? || to_uri.empty?

  if from_missing
    errors << ValidationError.create(
      field: :from_uri,
      message: "Source URI is required",
      constraint: "presence",
    )
  end

  if to_missing
    errors << ValidationError.create(
      field: :to_uri,
      message: "Target URI is required",
      constraint: "presence",
    )
  end

  # Only check equality if both URIs are present
  if !from_missing && !to_missing && from_uri == to_uri
    errors << ValidationError.create(
      field: :to_uri,
      message: "Target URI must be different from source URI",
      value: to_uri,
      constraint: "!= from_uri",
    )
  end

  errors.empty? ? ValidationResult.success : ValidationResult.failure(errors)
end

#validate!Object

Raise error if invalid



65
66
67
# File 'lib/lutaml/xml/schema/xsd/namespace_uri_remapping.rb', line 65

def validate!
  validate.validate!
end