Sha256: 97eab28378fa6b923f79a72d1be92cbf47d11cea8d74805a4e7c0659bd401054

Contents?: true

Size: 596 Bytes

Versions: 1

Compression:

Stored size: 596 Bytes

Contents

# lib/lutaml/model/yaml_adapter.rb
require "yaml"

module Lutaml
  module Model
    module YamlAdapter
      module Standard
        def self.to_yaml(model, *args)
          YAML.dump(model.hash_representation(:yaml), *args)
        end

        def self.from_yaml(yaml, klass)
          data = parse(yaml)
          mapped_attrs = klass.send(:apply_mappings, data, :yaml)
          klass.new(mapped_attrs)
        end

        def self.parse(yaml)
          YAML.safe_load(yaml, permitted_classes: [Date, Time, DateTime, Symbol, BigDecimal, Hash, Array])
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lutaml-model-0.1.0 lib/lutaml/model/yaml_adapter.rb