Module: Lutaml::Xml::Type::Configurable::ClassMethods

Defined in:
lib/lutaml/xml/type/configurable.rb

Overview

Class methods for XML configuration

Instance Method Summary collapse

Instance Method Details

#create_xml_mappingLutaml::Xml::Type::ValueXmlMapping

Create a new XML mapping instance

Returns:



150
151
152
# File 'lib/lutaml/xml/type/configurable.rb', line 150

def create_xml_mapping
  Lutaml::Xml::Type::ValueXmlMapping.new
end

#default_xsd_typeString

Default XSD type for this Value type

Override in subclasses to provide specific default XSD types.

Returns:

  • (String)

    the default XSD type



130
131
132
# File 'lib/lutaml/xml/type/configurable.rb', line 130

def default_xsd_type
  "xs:anyType"
end

#inherit_xml_mapping_from_parentLutaml::Xml::Type::ValueXmlMapping

Create a new XML mapping, inheriting from parent if available

Returns:



137
138
139
140
141
142
143
144
145
# File 'lib/lutaml/xml/type/configurable.rb', line 137

def inherit_xml_mapping_from_parent
  return create_xml_mapping if superclass == Lutaml::Model::Type::Value
  return create_xml_mapping unless superclass.respond_to?(:xml_mapping)

  parent_mapping = superclass.xml_mapping
  return create_xml_mapping unless parent_mapping

  parent_mapping.deep_dup
end

#inherited_namespaceClass, ...

Get inherited namespace from parent class

Returns:

  • (Class, Symbol, nil)

    parent’s namespace class if set



117
118
119
120
121
122
123
# File 'lib/lutaml/xml/type/configurable.rb', line 117

def inherited_namespace
  return nil if superclass == Lutaml::Model::Type::Value
  return nil unless superclass.respond_to?(:xml_mapping)

  parent_mapping = superclass.xml_mapping
  parent_mapping&.namespace_class || superclass.inherited_namespace
end

#inherited_xsd_typeString?

Get inherited xsd_type from parent class

Returns:

  • (String, nil)

    parent’s xsd_type if set



105
106
107
108
109
110
111
112
# File 'lib/lutaml/xml/type/configurable.rb', line 105

def inherited_xsd_type
  return nil if superclass == Lutaml::Model::Type::Value
  return nil unless superclass.respond_to?(:xsd_type)

  # Get parent's @xsd_type directly (not default_xsd_type)
  parent_xsd = superclass.instance_variable_get(:@xsd_type)
  parent_xsd || superclass.inherited_xsd_type
end

#namespace_classClass, ...

Get the namespace class for this Value type

Returns:

  • (Class, Symbol, nil)

    the namespace class or symbol



84
85
86
# File 'lib/lutaml/xml/type/configurable.rb', line 84

def namespace_class
  xml_mapping&.namespace_class || inherited_namespace
end

#namespace_prefixString?

Get the default namespace prefix for this Value type

Returns:

  • (String, nil)

    the namespace prefix



73
74
75
76
77
78
79
# File 'lib/lutaml/xml/type/configurable.rb', line 73

def namespace_prefix
  ns = namespace_class
  return nil unless ns
  return nil if %i[blank inherit].include?(ns)

  ns.prefix_default
end

#namespace_uriString?

Get the namespace URI for this Value type

Returns:

  • (String, nil)

    the namespace URI



62
63
64
65
66
67
68
# File 'lib/lutaml/xml/type/configurable.rb', line 62

def namespace_uri
  ns = namespace_class
  return nil unless ns
  return nil if %i[blank inherit].include?(ns)

  ns.uri
end

#xml { ... } ⇒ Lutaml::Xml::Type::ValueXmlMapping

XML configuration block for Value types

Provides unified XML configuration API for Type classes. Supports inheritance from parent types.

Examples:

Using xml block for configuration

class EmailType < Lutaml::Model::Type::String
  xml do
    namespace EmailNamespace
    xsd_type 'EmailAddress'
  end
end

Yields:

  • block for XML configuration

Returns:



44
45
46
47
48
49
50
# File 'lib/lutaml/xml/type/configurable.rb', line 44

def xml(&block)
  if block
    @xml_mapping ||= inherit_xml_mapping_from_parent # rubocop:disable Naming/MemoizedInstanceVariableName
    @xml_mapping.instance_eval(&block)
  end
  @xml_mapping ||= inherit_xml_mapping_from_parent # rubocop:disable Naming/MemoizedInstanceVariableName
end

#xml_mappingLutaml::Xml::Type::ValueXmlMapping?

Get the XML mapping for this Value type

Returns:



55
56
57
# File 'lib/lutaml/xml/type/configurable.rb', line 55

def xml_mapping
  @xml_mapping
end

#xsd_type(type_name = nil) ⇒ String

Class-level directive to set the XSD type name

Examples:

Setting XSD type

class CustomType < Lutaml::Model::Type::Value
  xsd_type 'ct:CustomType'
end

Parameters:

  • type_name (String, Symbol, Class, nil) (defaults to: nil)

    XSD type name, Type class, or nil

Returns:

  • (String)

    the XSD type name



97
98
99
100
# File 'lib/lutaml/xml/type/configurable.rb', line 97

def xsd_type(type_name = nil)
  @xsd_type = type_name if type_name
  @xsd_type || inherited_xsd_type || default_xsd_type
end