Class: Lutaml::Yamls::Adapter::Transform

Inherits:
KeyValue::Transform show all
Defined in:
lib/lutaml/yamls/adapter/transform.rb

Instance Attribute Summary

Attributes inherited from Model::Transform

#attributes, #context, #lutaml_register

Instance Method Summary collapse

Methods inherited from Model::Transform

data_to_model, #initialize, #model_class, model_to_data

Constructor Details

This class inherits a constructor from Lutaml::Model::Transform

Instance Method Details

#data_to_model(data, format, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lutaml/yamls/adapter/transform.rb', line 7

def data_to_model(data, format, options = {})
  mappings = defined_mappings_for(:yamls) || mappings_for(:yaml,
                                                          lutaml_register)

  if mappings.is_a?(Mapping) && mappings.yamls_sequence
    data_to_model_with_sequence(data, format, mappings.yamls_sequence,
                                options)
  else
    super(data, format, options.merge(mappings: mappings))
  end
end

#model_to_data(instance, _format, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lutaml/yamls/adapter/transform.rb', line 19

def model_to_data(instance, _format, options = {})
  mappings = defined_mappings_for(:yamls) || mappings_for(:yaml,
                                                          lutaml_register)

  if mappings.is_a?(Mapping) && mappings.yamls_sequence
    model_to_data_with_sequence(instance, mappings.yamls_sequence)
  else
    defined = defined_mappings_for(:yamls) || mappings_for(:yaml,
                                                           lutaml_register)
    super(instance, :yaml, options.merge(mappings: defined))
  end
end