Class: Lutaml::Xml::TypeNamespace::Reference
- Inherits:
-
Object
- Object
- Lutaml::Xml::TypeNamespace::Reference
- Defined in:
- lib/lutaml/xml/type_namespace/reference.rb
Overview
Value object representing a reference to a type namespace
Type namespaces are declared on attribute types via xml_namespace. This reference tracks the attribute, rule, and context for later resolution.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#mapper_class ⇒ Object
readonly
Returns the value of attribute mapper_class.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
-
#attribute_context? ⇒ Boolean
Check if this is for an attribute context.
-
#element_context? ⇒ Boolean
Check if this is for an element context.
-
#initialize(attribute, rule, context, mapper_class: nil) ⇒ Reference
constructor
A new instance of Reference.
-
#namespace_class(register) ⇒ XmlNamespace?
Get the namespace class from the type, resolving the register context from the mapper_class if available.
-
#type_class(register) ⇒ Class?
Get the type class from the attribute, resolving the register context from the mapper_class if available.
Constructor Details
#initialize(attribute, rule, context, mapper_class: nil) ⇒ Reference
Returns a new instance of Reference.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 17 def initialize(attribute, rule, context, mapper_class: nil) unless %i[ attribute element ].include?(context) raise ArgumentError, "Context must be :attribute or :element" end @attribute = attribute @rule = rule @context = context @mapper_class = mapper_class freeze end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
11 12 13 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 11 def attribute @attribute end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
11 12 13 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 11 def context @context end |
#mapper_class ⇒ Object (readonly)
Returns the value of attribute mapper_class.
11 12 13 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 11 def mapper_class @mapper_class end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
11 12 13 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 11 def rule @rule end |
Instance Method Details
#attribute_context? ⇒ Boolean
Check if this is for an attribute context
60 61 62 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 60 def attribute_context? @context == :attribute end |
#element_context? ⇒ Boolean
Check if this is for an element context
65 66 67 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 65 def element_context? @context == :element end |
#namespace_class(register) ⇒ XmlNamespace?
Get the namespace class from the type, resolving the register context from the mapper_class if available.
52 53 54 55 56 57 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 52 def namespace_class(register) type = type_class(register) return nil unless type.is_a?(Class) && type <= Lutaml::Model::Type::Value type.namespace_class end |
#type_class(register) ⇒ Class?
Get the type class from the attribute, resolving the register context from the mapper_class if available.
37 38 39 40 41 42 43 44 45 |
# File 'lib/lutaml/xml/type_namespace/reference.rb', line 37 def type_class(register) resolved = if @mapper_class Lutaml::Model::Register.resolve_for_child(@mapper_class, register) else register end @attribute.type(resolved) end |