Class: Lutaml::Xml::ParseSession

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

Overview

Per-parse context threaded through ModelTransform's mapping passes.

Bundles everything one data_to_model call needs — the parsed doc, the instance under construction, the effective register, and the flags derived from them — so apply_xml_mapping and value_for_rule take one object instead of a growing positional parameter list. Memoizes the per-parse lookups (mapping, namespace class, adopted document namespace) that every rule would otherwise recompute.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, instance, options, register) ⇒ ParseSession



16
17
18
19
20
21
# File 'lib/lutaml/xml/parse_session.rb', line 16

def initialize(doc, instance, options, register)
  @doc = doc
  @instance = instance
  @options = options
  @register = register
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



14
15
16
# File 'lib/lutaml/xml/parse_session.rb', line 14

def doc
  @doc
end

#instanceObject (readonly)

Returns the value of attribute instance.



14
15
16
# File 'lib/lutaml/xml/parse_session.rb', line 14

def instance
  @instance
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/lutaml/xml/parse_session.rb', line 14

def options
  @options
end

#registerObject (readonly)

Returns the value of attribute register.



14
15
16
# File 'lib/lutaml/xml/parse_session.rb', line 14

def register
  @register
end

Instance Method Details

#adopted_namespace_uriObject

The document's own namespace when it differs from the model's bound namespace (lenient, out-of-namespace documents). Adopted as an implicit alias for element matching (lutaml-model#754).



38
39
40
41
# File 'lib/lutaml/xml/parse_session.rb', line 38

def adopted_namespace_uri
  @adopted_namespace_uri ||=
    instance_is_serialize ? instance.original_namespace_uri : nil
end

#instance_is_serializeObject



23
24
25
# File 'lib/lutaml/xml/parse_session.rb', line 23

def instance_is_serialize
  @instance_is_serialize ||= instance.is_a?(::Lutaml::Model::Serialize)
end

#model_classObject



27
28
29
# File 'lib/lutaml/xml/parse_session.rb', line 27

def model_class
  @model_class ||= instance.class
end

#model_namespace_urisObject

Namespace URIs accepted for children of this model: the model's namespace URIs plus the adopted document namespace when present.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/lutaml/xml/parse_session.rb', line 45

def model_namespace_uris
  @model_namespace_uris ||=
    begin
      ns_class = instance_is_serialize ? xml_mapping&.namespace_class : nil
      uris = ns_class&.all_uris
      adopted = adopted_namespace_uri
      if ns_class && adopted && !uris&.include?(adopted)
        uris = (uris || []) + [adopted]
      end
      uris
    end
end

#xml_mappingObject



31
32
33
# File 'lib/lutaml/xml/parse_session.rb', line 31

def xml_mapping
  @xml_mapping ||= model_class.mappings_for(:xml, register)
end