Class: Lutaml::KeyValue::Adapter::Yaml::StandardAdapter

Inherits:
Document show all
Defined in:
lib/lutaml/key_value/adapter/yaml/standard_adapter.rb

Constant Summary collapse

FORMAT_SYMBOL =
:yaml
PERMITTED_CLASSES_BASE =
[Date, Time, DateTime, Symbol, ::Hash,
Array].freeze
PERMITTED_CLASSES =
if defined?(BigDecimal)
  PERMITTED_CLASSES_BASE + [BigDecimal]
else
  PERMITTED_CLASSES_BASE
end.freeze

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(yaml, _options = {}) ⇒ Object



21
22
23
# File 'lib/lutaml/key_value/adapter/yaml/standard_adapter.rb', line 21

def self.parse(yaml, _options = {})
  YAML.safe_load(yaml, permitted_classes: PERMITTED_CLASSES)
end

Instance Method Details

#to_yaml(options = {}) ⇒ Object



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

def to_yaml(options = {})
  # 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

  YAML.dump(attributes_to_serialize, options)
end