Class: Lutaml::Xml::ParseSession
- Inherits:
-
Object
- Object
- Lutaml::Xml::ParseSession
- 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
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
Instance Method Summary collapse
-
#adopted_namespace_uri ⇒ Object
The document's own namespace when it differs from the model's bound namespace (lenient, out-of-namespace documents).
-
#initialize(doc, instance, options, register) ⇒ ParseSession
constructor
A new instance of ParseSession.
- #instance_is_serialize ⇒ Object
- #model_class ⇒ Object
-
#model_namespace_uris ⇒ Object
Namespace URIs accepted for children of this model: the model's namespace URIs plus the adopted document namespace when present.
- #xml_mapping ⇒ Object
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, , register) @doc = doc @instance = instance = @register = register end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
14 15 16 |
# File 'lib/lutaml/xml/parse_session.rb', line 14 def doc @doc end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
14 15 16 |
# File 'lib/lutaml/xml/parse_session.rb', line 14 def instance @instance end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/lutaml/xml/parse_session.rb', line 14 def end |
#register ⇒ Object (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_uri ⇒ Object
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_serialize ⇒ Object
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_class ⇒ Object
27 28 29 |
# File 'lib/lutaml/xml/parse_session.rb', line 27 def model_class @model_class ||= instance.class end |
#model_namespace_uris ⇒ Object
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_mapping ⇒ Object
31 32 33 |
# File 'lib/lutaml/xml/parse_session.rb', line 31 def xml_mapping @xml_mapping ||= model_class.mappings_for(:xml, register) end |