Module: Lutaml::Xml::W3c

Extended by:
W3c
Included in:
W3c
Defined in:
lib/lutaml/xml/w3c.rb,
lib/lutaml/xml/w3c/registration.rb

Overview

W3C Standard XML Namespaces

These namespace classes represent the standard W3C-defined XML namespaces that have special semantics and reserved prefixes.

Per W3C specifications:

  • xml: prefix is ALWAYS bound to www.w3.org/XML/1998/namespace

  • xsi: prefix is conventionally used for XMLSchema-instance

  • These prefixes should never be overridden

Defined Under Namespace

Classes: XlinkActuateType, XlinkArcroleType, XlinkHrefType, XlinkNamespace, XlinkRoleType, XlinkShowType, XlinkTitleType, XlinkTypeAttrType, XmlBaseType, XmlIdType, XmlLangType, XmlNamespace, XmlSpaceType, XsNamespace, XsiNamespace, XsiNil, XsiNoNamespaceSchemaLocationType, XsiSchemaLocationType, XsiType

Constant Summary collapse

W3C_TYPES =

W3C types mapped to their symbol identifiers for Type registry

{
  xml_lang: XmlLangType,
  xml_space: XmlSpaceType,
  xml_base: XmlBaseType,
  xml_id: XmlIdType,
  xsi_type: XsiType,
  xsi_nil: XsiNil,
  xsi_schema_location: XsiSchemaLocationType,
  xsi_no_namespace_schema_location: XsiNoNamespaceSchemaLocationType,
  xlink_href: XlinkHrefType,
  xlink_type: XlinkTypeAttrType,
  xlink_role: XlinkRoleType,
  xlink_arcrole: XlinkArcroleType,
  xlink_title: XlinkTitleType,
  xlink_show: XlinkShowType,
  xlink_actuate: XlinkActuateType,
}.freeze

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object

Automatically register types when a constant is accessed via const_missing. This ensures symbol-based type access works even if autoload order causes w3c.rb to load before lutaml-model’s Type module.



60
61
62
63
# File 'lib/lutaml/xml/w3c/registration.rb', line 60

def const_missing(name)
  register_types!
  const_get(name)
end

#register_types!Boolean

Register all W3C types with the Type registry. Called lazily when types are first accessed.

Returns:

  • (Boolean)

    true if registration succeeded or already done



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/lutaml/xml/w3c/registration.rb', line 31

def register_types!
  return true if @types_registered && registered?

  if defined?(Lutaml::Model::Type)
    W3C_TYPES.each do |symbol, type_class|
      Lutaml::Model::Type.register(symbol, type_class)
    end
    @types_registered = true
  end
  @types_registered
end

#registered?Boolean

Check if W3C types are actually registered in the Type registry.

Returns:

  • (Boolean)

    true if all W3C types are registered



46
47
48
49
50
51
52
53
54
55
# File 'lib/lutaml/xml/w3c/registration.rb', line 46

def registered?
  return false unless defined?(Lutaml::Model::Type)
  return false unless Lutaml::Model::Type.instance_variable_defined?(:@registry)

  W3C_TYPES.keys.all? do |symbol|
    Lutaml::Model::Type.lookup_ignoring_fallback(symbol)
  end
rescue StandardError
  false
end