Module: Lutaml::Xml::HoistingAlgorithm
- Defined in:
- lib/lutaml/xml/hoisting_algorithm.rb
Overview
HoistingAlgorithm defines strategies for namespace declaration placement.
When serializing XML, we must decide WHERE to declare each namespace. This module provides swappable algorithms for different hoisting strategies.
Key concepts:
-
namespace_scope makes namespaces ELIGIBLE for hoisting to any parent
-
The algorithm determines WHERE eligible namespaces are actually declared
-
Round-trip preservation takes priority (use stored plan if available)
Algorithm selection priority:
-
PRESERVED - if stored plan exists (round-trip fidelity)
-
User option - to_xml(hoisting: :lca)
-
Class config - xml { hoisting_algorithm :first_usage }
-
Global default - Config.default_hoisting_algorithm
Defined Under Namespace
Classes: Base, FirstUsage, LCA, NamespaceScopeOnly, Preserved
Constant Summary collapse
- ALGORITHMS =
Registry of available algorithms
{ lca: LCA, first_usage: FirstUsage, namespace_scope_only: NamespaceScopeOnly, preserved: Preserved, }.freeze
Class Method Summary collapse
-
.default ⇒ Object
Default algorithm.
-
.get(name, **options) ⇒ Base
Get algorithm instance by name.
Class Method Details
.default ⇒ Object
Default algorithm
229 230 231 |
# File 'lib/lutaml/xml/hoisting_algorithm.rb', line 229 def self.default LCA.new end |
.get(name, **options) ⇒ Base
Get algorithm instance by name
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/lutaml/xml/hoisting_algorithm.rb', line 213 def self.get(name, **) klass = ALGORITHMS[name] unless klass raise ArgumentError, "Unknown hoisting algorithm: #{name}" end if klass == Preserved && [:fallback] fallback = get([:fallback]) klass.new(fallback: fallback) else klass.new end end |