Class: Lutaml::YamlLd::Adapter

Inherits:
KeyValue::Document show all
Defined in:
lib/lutaml/yamlld/adapter.rb

Constant Summary collapse

PERMITTED_CLASSES =
Lutaml::Yaml::Adapter::StandardAdapter::PERMITTED_CLASSES

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



10
11
12
# File 'lib/lutaml/yamlld/adapter.rb', line 10

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

Instance Method Details

#to_yamlld(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/lutaml/yamlld/adapter.rb', line 14

def to_yamlld(options = {})
  attributes_to_serialize =
    if @attributes.is_a?(Lutaml::KeyValue::DataModel::Element)
      @attributes.to_hash["__root__"]
    else
      @attributes
    end
  YAML.dump(attributes_to_serialize, options)
end