Class: Lutaml::Xml::Decisions::Rules::InheritFromParentRule

Inherits:
DecisionRule
  • Object
show all
Defined in:
lib/lutaml/xml/decisions/rules/inherit_from_parent_rule.rb

Overview

Priority 0: Inherit parent's default namespace

When parent uses default format (xmlns="uri"), children in same namespace should inherit by having NO prefix (not parent's prefix!)

This handles two cases:

  1. Parent has explicit namespace_class in same namespace
  2. Parent has default namespace declared (child's namespace matches parent's default)

Instance Method Summary collapse

Methods inherited from DecisionRule

#<=>, #name

Instance Method Details

#applies?(context) ⇒ Boolean

Applies when:

  • Parent uses default format
  • Element is in same namespace as parent (explicit OR via default)
  • Child does NOT have its own prefix from deserialization (if child has its own prefix, FormatPreservationRule should handle it)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lutaml/xml/decisions/rules/inherit_from_parent_rule.rb', line 26

def applies?(context)
  return false unless context.has_namespace?
  return false unless context.parent_uses_default_format?

  # If child has its own used prefix from deserialization, don't inherit.
  # Let FormatPreservationRule handle it to preserve the child's prefix.
  return false if context.element_used_prefix

  # Case 1: Both parent and child have explicit namespace_class in same namespace
  return true if context.same_namespace_as_parent?

  # Case 2: Parent has default namespace declared and child's namespace matches it
  context.namespace_matches_parent_default?
end

#decide(context) ⇒ Object

Decision: Use default format to inherit



42
43
44
45
46
47
# File 'lib/lutaml/xml/decisions/rules/inherit_from_parent_rule.rb', line 42

def decide(context)
  Decision.default(
    namespace_class: context.namespace_class,
    reason: "Priority 0: Inherit parent's default namespace",
  )
end

#priorityObject

Priority 0 - Highest priority



17
18
19
# File 'lib/lutaml/xml/decisions/rules/inherit_from_parent_rule.rb', line 17

def priority
  0
end