Class: Lutaml::Xml::HoistingAlgorithm::Preserved

Inherits:
Base
  • Object
show all
Defined in:
lib/lutaml/xml/hoisting_algorithm.rb

Overview

Preserved Algorithm

Uses hoisting locations from stored DeclarationPlan. Critical for round-trip fidelity - changing hoist locations could break readers.

If no stored plan or element not found, falls back to provided fallback algorithm.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fallback: LCA.new) ⇒ Preserved

Returns a new instance of Preserved.

Parameters:

  • fallback (Base) (defaults to: LCA.new)

    Algorithm to use when no stored location exists



150
151
152
# File 'lib/lutaml/xml/hoisting_algorithm.rb', line 150

def initialize(fallback: LCA.new)
  @fallback = fallback
end

Instance Attribute Details

#fallbackObject (readonly)

Returns the value of attribute fallback.



147
148
149
# File 'lib/lutaml/xml/hoisting_algorithm.rb', line 147

def fallback
  @fallback
end

Instance Method Details

#should_hoist_here?(element, namespace_class, needs, context) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/lutaml/xml/hoisting_algorithm.rb', line 154

def should_hoist_here?(element, namespace_class, needs, context)
  stored_plan = context[:stored_plan]

  if stored_plan && stored_location_exists?(stored_plan, element,
                                            namespace_class)
    # Use stored location
    stored_declares_here?(stored_plan, element, namespace_class)
  else
    # Fall back to configured algorithm
    fallback.should_hoist_here?(element, namespace_class, needs,
                                context)
  end
end