Class: Lutaml::KeyValue::Adapter::Toml::TeptrisAdapter

Inherits:
Document show all
Defined in:
lib/lutaml/key_value/adapter/toml/teptris_adapter.rb

Instance Attribute Summary

Attributes inherited from Document

#attributes, #register

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Document

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

Constructor Details

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

Class Method Details

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

teptris is required lazily (in parse/to_toml), NOT at file load: a platform gem whose native library is broken must degrade to detection-fallback + skipped specs, never crash unrelated loads. The gem's own require raises a clear LoadError ("no fallback by design") for that case.



20
21
22
23
# File 'lib/lutaml/key_value/adapter/toml/teptris_adapter.rb', line 20

def self.parse(toml, _options = {})
  require "teptris"
  Teptris::TOML.load(toml)
end

Instance Method Details

#to_tomlObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lutaml/key_value/adapter/toml/teptris_adapter.rb', line 25

def to_toml(*)
  require "teptris"
  # Handle KeyValueElement input (new symmetric architecture)
  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

  Teptris::TOML.dump(attributes_to_serialize)
end