Class: Lutaml::Yaml::Adapter::YeptrisAdapter

Inherits:
StandardAdapter show all
Defined in:
lib/lutaml/yaml/adapter/yeptris_adapter.rb

Overview

YAML over the yeptris engine (libyeptris C11). Uses the native Yeptris::YAML surface, which does not rebind or interact with the Psych constant, so it coexists with the standard adapter in one process. Inherits the document/generation contract; only the engine calls differ.

Semantic notes vs the standard adapter's Psych.safe_load: implicit typing is parity-verified (compat_11 schema); anchors and aliases always resolve; a tagged value without a core type materializes as plain data instead of raising DisallowedClass; parse failures surface as Psych::SyntaxError like the standard adapter's (the engine's own ParseError is re-raised under the standard class).

Constant Summary

Constants inherited from StandardAdapter

StandardAdapter::FORMAT_SYMBOL, StandardAdapter::PERMITTED_CLASSES, StandardAdapter::PERMITTED_CLASSES_BASE

Instance Attribute Summary

Attributes inherited from KeyValue::Document

#attributes, #register

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from KeyValue::Document

#[], #[]=, #initialize, #key?, #to_h

Constructor Details

This class inherits a constructor from Lutaml::KeyValue::Document

Class Method Details

.parse(yaml, _options = {}) ⇒ Object

yeptris is required lazily: the ruby-platform variant installs everywhere but only loads where libyeptris exists (no Windows prebuilts) — a broken install must degrade to detection fallback, never crash loads.



26
27
28
29
30
31
32
33
# File 'lib/lutaml/yaml/adapter/yeptris_adapter.rb', line 26

def self.parse(yaml, _options = {})
  require_engine
  require "yeptris/yaml"
  # rubocop:disable-next Naming/VariableNumber -- upstream schema literal
  Yeptris::YAML.load(yaml, schema: :compat_11)
rescue Yeptris::ParseError => e
  raise syntax_error(e)
end

Instance Method Details

#to_yaml(_options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lutaml/yaml/adapter/yeptris_adapter.rb', line 62

def to_yaml(_options = {})
  attributes_to_serialize = if @attributes.is_a?(Lutaml::KeyValue::DataModel::Element)
                              # Unwrap __root__ wrapper to get actual content
                              @attributes.to_hash["__root__"]
                            else
                              # Legacy Hash input (backward compatibility)
                              @attributes
                            end

  # Generation must match the standard (Psych) adapter's output
  # byte-for-byte: document separator, quoting of digit-leading
  # strings, flow styles. The neutral Yeptris::YAML.dump is
  # deliberately headerless, so parity goes through the
  # Psych-compatible face of the same engine.
  require "yeptris/psych"
  Yeptris::Psych.dump(attributes_to_serialize)
end