Class: Lutaml::Xml::Schema::Xsd::SchemaLocationMapping

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

Overview

Represents a schema location mapping for resolving import/include paths

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::Serialize

#attr_value, #attribute_exist?, #extract_register_id, included, #init_deserialization_state, #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, #validate!, #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

#mixed_content?

Constructor Details

#initialize(attributes = nil, from: nil, to: nil, pattern: nil) ⇒ SchemaLocationMapping

Override initialize to auto-detect Regexp patterns Supports both hash argument (for Lutaml::Model) and keyword arguments

Parameters:

  • attributes (Hash) (defaults to: nil)

    Attributes hash (for deserialization)

  • from (String, Regexp) (defaults to: nil)

    The source pattern

  • to (String) (defaults to: nil)

    The target path

  • pattern (Boolean, nil) (defaults to: nil)

    Explicit pattern flag (optional)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lutaml/xml/schema/xsd/schema_location_mapping.rb', line 30

def initialize(attributes = nil, from: nil, to: nil, pattern: nil,
      **)
  # Handle hash argument from Lutaml::Model deserialization
  if attributes.is_a?(Hash)
    from = attributes[:from] || attributes["from"]
    to = attributes[:to] || attributes["to"]
    pattern = attributes[:pattern] || attributes["pattern"]
  end

  # Auto-detect if from is a Regexp
  detected_pattern = from.is_a?(Regexp)

  # Convert Regexp to source string for storage
  from_str = detected_pattern ? from.source : from

  # Use explicit pattern flag if provided, otherwise use detected value
  final_pattern = pattern.nil? ? detected_pattern : pattern

  super(from: from_str, to: to, pattern: final_pattern, **)
end

Dynamic Method Handling

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

Class Method Details

.from_hash(mapping) ⇒ SchemaLocationMapping

Convert hash-based mapping to SchemaLocationMapping instance

Parameters:

  • mapping (Hash)

    Hash with :from/:to or “from”/“to” keys

Returns:



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

def self.from_hash(mapping)
  from = mapping[:from] || mapping["from"]
  to = mapping[:to] || mapping["to"]
  pattern = mapping[:pattern] || mapping["pattern"]

  new(from: from, to: to, pattern: pattern)
end

Instance Method Details

#to_glob_formatHash

Convert to hash format compatible with Glob.schema_mappings

Returns:

  • (Hash)


64
65
66
67
68
69
# File 'lib/lutaml/xml/schema/xsd/schema_location_mapping.rb', line 64

def to_glob_format
  {
    from: pattern ? Regexp.new(from) : from,
    to: to,
  }
end