Module: Lutaml::Xml::SharedDsl
- Included in:
- Type::ValueXmlMapping
- Defined in:
- lib/lutaml/xml/shared_dsl.rb
Overview
Shared DSL methods for XML configuration
This module provides common DSL methods used by both Model classes (via Lutaml::Xml::Mapping) and Type classes (via Lutaml::Model::Type::ValueXmlMapping).
Constant Summary collapse
- VALID_XSD_TYPE_SYMBOLS =
Valid XSD type symbols for shorthand notation
%i[ string integer float double decimal boolean date time datetime duration anyuri qname base64binary hexbinary ].freeze
Instance Method Summary collapse
-
#resolve_xsd_type(type) ⇒ String
Resolve XSD type from various input formats.
-
#resolve_xsd_type_from_class(klass) ⇒ String
Resolve XSD type from a class.
-
#resolve_xsd_type_from_symbol(sym) ⇒ String
Resolve XSD type from a symbol.
-
#validate_namespace_class!(ns_class) ⇒ Object
Validate that a namespace class is valid.
Instance Method Details
#resolve_xsd_type(type) ⇒ String
Resolve XSD type from various input formats
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lutaml/xml/shared_dsl.rb', line 57 def resolve_xsd_type(type) # Use ::Symbol and ::Class to refer to Ruby built-in classes case type when ::Symbol resolve_xsd_type_from_symbol(type) when ::Class resolve_xsd_type_from_class(type) else raise ArgumentError, "xsd_type must be a Symbol or Class, got #{type.class}" end end |
#resolve_xsd_type_from_class(klass) ⇒ String
Resolve XSD type from a class
108 109 110 111 112 113 114 115 116 |
# File 'lib/lutaml/xml/shared_dsl.rb', line 108 def resolve_xsd_type_from_class(klass) unless klass.is_a?(::Class) && klass < Lutaml::Model::Type::Value raise ArgumentError, "xsd_type class must inherit from Lutaml::Model::Type::Value, " \ "got #{klass.inspect}" end klass.default_xsd_type end |
#resolve_xsd_type_from_symbol(sym) ⇒ String
Resolve XSD type from a symbol
93 94 95 96 97 98 99 100 101 |
# File 'lib/lutaml/xml/shared_dsl.rb', line 93 def resolve_xsd_type_from_symbol(sym) unless VALID_XSD_TYPE_SYMBOLS.include?(sym) raise ArgumentError, "Unknown type symbol: #{sym.inspect}. " \ "Valid symbols: #{VALID_XSD_TYPE_SYMBOLS.join(', ')}" end "xs:#{sym}" end |
#validate_namespace_class!(ns_class) ⇒ Object
Validate that a namespace class is valid
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lutaml/xml/shared_dsl.rb', line 32 def validate_namespace_class!(ns_class) return if ns_class.nil? return if %i[blank inherit].include?(ns_class) # Use ::Class to refer to Ruby built-in Class (avoiding Lutaml::Model::Type::Class) valid = ns_class.is_a?(::Class) && defined?(::Lutaml::Xml::Namespace) && ns_class < ::Lutaml::Xml::Namespace unless valid raise Lutaml::Xml::Error::InvalidNamespaceError.new( expected: "XmlNamespace class, :inherit, or :blank", got: ns_class, ) end end |