Class: Lutaml::Xml::Decisions::Rules::HoistedOnParentRule
- Inherits:
-
DecisionRule
- Object
- DecisionRule
- Lutaml::Xml::Decisions::Rules::HoistedOnParentRule
- Defined in:
- lib/lutaml/xml/decisions/rules/hoisted_on_parent_rule.rb
Overview
Priority 0.5: Namespace was hoisted on parent
When parent declared a namespace (as prefix OR default), children in that namespace MUST use the same format. If parent used default format (xmlns=“uri”), children inherit with NO prefix. If parent used prefix format (xmlns:p=“uri”), children use the same prefix.
Instance Method Summary collapse
-
#applies?(context) ⇒ Boolean
Applies when namespace is hoisted on parent BUT: If child has its own used prefix from deserialization, don’t let this rule override.
-
#decide(context) ⇒ Object
Decision: Use the same format as parent (prefix or default).
-
#priority ⇒ Object
Priority 0.5 - Second highest.
Methods inherited from DecisionRule
Instance Method Details
#applies?(context) ⇒ Boolean
Applies when namespace is hoisted on parent BUT: If child has its own used prefix from deserialization, don’t let this rule override. Let FormatPreservationRule handle it.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lutaml/xml/decisions/rules/hoisted_on_parent_rule.rb', line 23 def applies?(context) return false unless context.has_namespace? # If child has its own used prefix from deserialization, don't apply. # Let FormatPreservationRule handle it to preserve the child's prefix. return false if context.element_used_prefix # Apply if this element's namespace is hoisted on parent # (either as default or with a prefix) # Children should inherit the parent's format context.hoisted_on_parent? end |
#decide(context) ⇒ Object
Decision: Use the same format as parent (prefix or default)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/lutaml/xml/decisions/rules/hoisted_on_parent_rule.rb', line 37 def decide(context) prefix = context.hoisted_prefix_on_parent # CRITICAL: If parent hoisted as default (prefix=nil), child must inherit # with default format (no prefix). If parent hoisted as prefix, child uses # that same prefix. if prefix.nil? Decision.default( namespace_class: context.namespace_class, reason: "Priority 0.5: Namespace hoisted on parent as default - inherit with no prefix", ) else Decision.prefix( prefix: prefix, namespace_class: context.namespace_class, reason: "Priority 0.5: Namespace hoisted on parent as prefix - use parent's prefix", ) end end |
#priority ⇒ Object
Priority 0.5 - Second highest
16 17 18 |
# File 'lib/lutaml/xml/decisions/rules/hoisted_on_parent_rule.rb', line 16 def priority 0.5 end |