lutaml-model 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/.rubocop_todo.yml +49 -48
  4. data/Gemfile +4 -1
  5. data/README.adoc +791 -143
  6. data/RELEASE_NOTES.adoc +346 -0
  7. data/docs/custom_adapters.adoc +144 -0
  8. data/lib/lutaml/model/attribute.rb +17 -11
  9. data/lib/lutaml/model/config.rb +48 -42
  10. data/lib/lutaml/model/error/polymorphic_error.rb +7 -2
  11. data/lib/lutaml/model/format_registry.rb +41 -0
  12. data/lib/lutaml/model/hash/document.rb +11 -0
  13. data/lib/lutaml/model/hash/mapping.rb +19 -0
  14. data/lib/lutaml/model/hash/mapping_rule.rb +9 -0
  15. data/lib/lutaml/model/hash/standard_adapter.rb +17 -0
  16. data/lib/lutaml/model/hash/transform.rb +8 -0
  17. data/lib/lutaml/model/hash.rb +21 -0
  18. data/lib/lutaml/model/json/document.rb +11 -0
  19. data/lib/lutaml/model/json/mapping.rb +19 -0
  20. data/lib/lutaml/model/json/mapping_rule.rb +9 -0
  21. data/lib/lutaml/model/{json_adapter → json}/multi_json_adapter.rb +4 -5
  22. data/lib/lutaml/model/{json_adapter/standard_json_adapter.rb → json/standard_adapter.rb} +5 -3
  23. data/lib/lutaml/model/json/transform.rb +8 -0
  24. data/lib/lutaml/model/json.rb +21 -0
  25. data/lib/lutaml/model/key_value_document.rb +27 -0
  26. data/lib/lutaml/model/mapping/key_value_mapping.rb +8 -4
  27. data/lib/lutaml/model/mapping/mapping.rb +13 -0
  28. data/lib/lutaml/model/mapping/mapping_rule.rb +7 -6
  29. data/lib/lutaml/model/serialization_adapter.rb +22 -0
  30. data/lib/lutaml/model/serialize.rb +146 -521
  31. data/lib/lutaml/model/services/logger.rb +54 -0
  32. data/lib/lutaml/model/services/transformer.rb +48 -0
  33. data/lib/lutaml/model/services.rb +2 -0
  34. data/lib/lutaml/model/toml/document.rb +11 -0
  35. data/lib/lutaml/model/toml/mapping.rb +27 -0
  36. data/lib/lutaml/model/toml/mapping_rule.rb +9 -0
  37. data/lib/lutaml/model/{toml_adapter → toml}/toml_rb_adapter.rb +3 -3
  38. data/lib/lutaml/model/toml/tomlib_adapter.rb +19 -0
  39. data/lib/lutaml/model/toml/transform.rb +8 -0
  40. data/lib/lutaml/model/toml.rb +30 -0
  41. data/lib/lutaml/model/transform/key_value_transform.rb +291 -0
  42. data/lib/lutaml/model/transform/xml_transform.rb +239 -0
  43. data/lib/lutaml/model/transform.rb +78 -0
  44. data/lib/lutaml/model/type/value.rb +6 -9
  45. data/lib/lutaml/model/uninitialized_class.rb +1 -1
  46. data/lib/lutaml/model/utils.rb +30 -0
  47. data/lib/lutaml/model/version.rb +1 -1
  48. data/lib/lutaml/model/{xml_adapter → xml}/builder/nokogiri.rb +2 -2
  49. data/lib/lutaml/model/{xml_adapter → xml}/builder/oga.rb +10 -10
  50. data/lib/lutaml/model/{xml_adapter → xml}/builder/ox.rb +1 -1
  51. data/lib/lutaml/model/{xml_adapter/xml_document.rb → xml/document.rb} +6 -7
  52. data/lib/lutaml/model/xml/element.rb +32 -0
  53. data/lib/lutaml/model/xml/mapping.rb +410 -0
  54. data/lib/lutaml/model/xml/mapping_rule.rb +141 -0
  55. data/lib/lutaml/model/xml/nokogiri_adapter.rb +232 -0
  56. data/lib/lutaml/model/{xml_adapter → xml}/oga/document.rb +1 -1
  57. data/lib/lutaml/model/{xml_adapter → xml}/oga/element.rb +3 -1
  58. data/lib/lutaml/model/xml/oga_adapter.rb +171 -0
  59. data/lib/lutaml/model/xml/ox_adapter.rb +215 -0
  60. data/lib/lutaml/model/xml/transform.rb +8 -0
  61. data/lib/lutaml/model/{xml_adapter → xml}/xml_attribute.rb +1 -1
  62. data/lib/lutaml/model/{xml_adapter → xml}/xml_element.rb +6 -3
  63. data/lib/lutaml/model/{xml_adapter → xml}/xml_namespace.rb +1 -1
  64. data/lib/lutaml/model/xml.rb +31 -0
  65. data/lib/lutaml/model/xml_adapter/element.rb +11 -25
  66. data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +6 -223
  67. data/lib/lutaml/model/xml_adapter/oga_adapter.rb +13 -163
  68. data/lib/lutaml/model/xml_adapter/ox_adapter.rb +10 -207
  69. data/lib/lutaml/model/yaml/document.rb +10 -0
  70. data/lib/lutaml/model/yaml/mapping.rb +19 -0
  71. data/lib/lutaml/model/yaml/mapping_rule.rb +9 -0
  72. data/lib/lutaml/model/{yaml_adapter/standard_yaml_adapter.rb → yaml/standard_adapter.rb} +4 -3
  73. data/lib/lutaml/model/yaml/transform.rb +8 -0
  74. data/lib/lutaml/model/yaml.rb +21 -0
  75. data/lib/lutaml/model.rb +39 -4
  76. data/lutaml-model.gemspec +0 -4
  77. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +4 -4
  78. data/spec/lutaml/model/cdata_spec.rb +7 -7
  79. data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +598 -0
  80. data/spec/lutaml/model/custom_vobject_adapter_spec.rb +1226 -0
  81. data/spec/lutaml/model/group_spec.rb +18 -7
  82. data/spec/lutaml/model/hash/adapter_spec.rb +255 -0
  83. data/spec/lutaml/model/json_adapter_spec.rb +6 -6
  84. data/spec/lutaml/model/key_value_mapping_spec.rb +25 -1
  85. data/spec/lutaml/model/mixed_content_spec.rb +24 -24
  86. data/spec/lutaml/model/multiple_mapping_spec.rb +5 -5
  87. data/spec/lutaml/model/ordered_content_spec.rb +6 -6
  88. data/spec/lutaml/model/polymorphic_spec.rb +178 -0
  89. data/spec/lutaml/model/root_mappings_spec.rb +3 -3
  90. data/spec/lutaml/model/schema/xml_compiler_spec.rb +6 -6
  91. data/spec/lutaml/model/serializable_spec.rb +179 -103
  92. data/spec/lutaml/model/toml_adapter_spec.rb +6 -6
  93. data/spec/lutaml/model/toml_spec.rb +51 -0
  94. data/spec/lutaml/model/transformation_spec.rb +72 -15
  95. data/spec/lutaml/model/uninitialized_class_spec.rb +96 -0
  96. data/spec/lutaml/model/xml/namespace_spec.rb +57 -0
  97. data/spec/lutaml/model/xml/xml_element_spec.rb +1 -1
  98. data/spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb +2 -2
  99. data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
  100. data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
  101. data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +6 -6
  102. data/spec/lutaml/model/xml_adapter_spec.rb +6 -6
  103. data/spec/lutaml/model/xml_mapping_rule_spec.rb +3 -3
  104. data/spec/lutaml/model/xml_mapping_spec.rb +26 -14
  105. data/spec/lutaml/model/xml_spec.rb +63 -0
  106. data/spec/lutaml/model/yaml_adapter_spec.rb +3 -5
  107. data/spec/spec_helper.rb +3 -3
  108. metadata +64 -59
  109. data/lib/lutaml/model/json_adapter/json_document.rb +0 -20
  110. data/lib/lutaml/model/json_adapter/json_object.rb +0 -28
  111. data/lib/lutaml/model/loggable.rb +0 -15
  112. data/lib/lutaml/model/mapping/json_mapping.rb +0 -17
  113. data/lib/lutaml/model/mapping/toml_mapping.rb +0 -25
  114. data/lib/lutaml/model/mapping/xml_mapping.rb +0 -389
  115. data/lib/lutaml/model/mapping/xml_mapping_rule.rb +0 -139
  116. data/lib/lutaml/model/mapping/yaml_mapping.rb +0 -17
  117. data/lib/lutaml/model/mapping.rb +0 -14
  118. data/lib/lutaml/model/toml_adapter/toml_document.rb +0 -20
  119. data/lib/lutaml/model/toml_adapter/toml_object.rb +0 -28
  120. data/lib/lutaml/model/toml_adapter/tomlib_adapter.rb +0 -20
  121. data/lib/lutaml/model/toml_adapter.rb +0 -6
  122. data/lib/lutaml/model/yaml_adapter/yaml_document.rb +0 -20
  123. data/lib/lutaml/model/yaml_adapter/yaml_object.rb +0 -28
  124. data/lib/lutaml/model/yaml_adapter.rb +0 -8
@@ -1,389 +0,0 @@
1
- require_relative "xml_mapping_rule"
2
-
3
- module Lutaml
4
- module Model
5
- class XmlMapping
6
- include Lutaml::Model::Loggable
7
-
8
- TYPES = {
9
- attribute: :map_attribute,
10
- element: :map_element,
11
- content: :map_content,
12
- all_content: :map_all,
13
- }.freeze
14
-
15
- attr_reader :root_element,
16
- :namespace_uri,
17
- :namespace_prefix,
18
- :mixed_content,
19
- :ordered,
20
- :element_sequence
21
-
22
- def initialize
23
- @elements = {}
24
- @attributes = {}
25
- @element_sequence = []
26
- @content_mapping = nil
27
- @raw_mapping = nil
28
- @mixed_content = false
29
- @format = :xml
30
- end
31
-
32
- alias mixed_content? mixed_content
33
- alias ordered? ordered
34
-
35
- def root(name, mixed: false, ordered: false)
36
- @root_element = name
37
- @mixed_content = mixed
38
- @ordered = ordered || mixed # mixed contenet will always be ordered
39
- end
40
-
41
- def root?
42
- !!root_element
43
- end
44
-
45
- def no_root
46
- @no_root = true
47
- end
48
-
49
- def no_root?
50
- !!@no_root
51
- end
52
-
53
- def prefixed_root
54
- if namespace_uri && namespace_prefix
55
- "#{namespace_prefix}:#{root_element}"
56
- else
57
- root_element
58
- end
59
- end
60
-
61
- def namespace(uri, prefix = nil)
62
- raise Lutaml::Model::NoRootNamespaceError if no_root?
63
-
64
- @namespace_uri = uri
65
- @namespace_prefix = prefix
66
- end
67
-
68
- # rubocop:disable Metrics/ParameterLists
69
- def map_element(
70
- name,
71
- to: nil,
72
- render_nil: false,
73
- render_default: false,
74
- render_empty: false,
75
- treat_nil: :nil,
76
- treat_empty: :empty,
77
- treat_omitted: :nil,
78
- with: {},
79
- delegate: nil,
80
- cdata: false,
81
- polymorphic: {},
82
- namespace: (namespace_set = false
83
- nil),
84
- prefix: (prefix_set = false
85
- nil),
86
- transform: {},
87
- value_map: {}
88
- )
89
- validate!(
90
- name, to, with, render_nil, render_empty, type: TYPES[:element]
91
- )
92
-
93
- rule = XmlMappingRule.new(
94
- name,
95
- to: to,
96
- render_nil: render_nil,
97
- render_default: render_default,
98
- render_empty: render_empty,
99
- treat_nil: treat_nil,
100
- treat_empty: treat_empty,
101
- treat_omitted: treat_omitted,
102
- with: with,
103
- delegate: delegate,
104
- cdata: cdata,
105
- namespace: namespace,
106
- default_namespace: namespace_uri,
107
- prefix: prefix,
108
- polymorphic: polymorphic,
109
- namespace_set: namespace_set != false,
110
- prefix_set: prefix_set != false,
111
- transform: transform,
112
- value_map: value_map,
113
- )
114
- @elements[rule.namespaced_name] = rule
115
- end
116
-
117
- def map_attribute(
118
- name,
119
- to: nil,
120
- render_nil: false,
121
- render_default: false,
122
- render_empty: false,
123
- with: {},
124
- delegate: nil,
125
- polymorphic_map: {},
126
- namespace: (namespace_set = false
127
- nil),
128
- prefix: (prefix_set = false
129
- nil),
130
- value_map: {}
131
- )
132
- validate!(
133
- name, to, with, render_nil, render_empty, type: TYPES[:attribute]
134
- )
135
-
136
- warn_auto_handling(name) if name == "schemaLocation"
137
-
138
- rule = XmlMappingRule.new(
139
- name,
140
- to: to,
141
- render_nil: render_nil,
142
- render_default: render_default,
143
- with: with,
144
- delegate: delegate,
145
- namespace: namespace,
146
- prefix: prefix,
147
- attribute: true,
148
- polymorphic_map: polymorphic_map,
149
- default_namespace: namespace_uri,
150
- namespace_set: namespace_set != false,
151
- prefix_set: prefix_set != false,
152
- value_map: value_map,
153
- )
154
- @attributes[rule.namespaced_name] = rule
155
- end
156
-
157
- # rubocop:enable Metrics/ParameterLists
158
-
159
- def map_content(
160
- to: nil,
161
- render_nil: false,
162
- render_default: false,
163
- render_empty: false,
164
- with: {},
165
- delegate: nil,
166
- mixed: false,
167
- cdata: false,
168
- value_map: {}
169
- )
170
- validate!(
171
- "content", to, with, render_nil, render_empty, type: TYPES[:content]
172
- )
173
-
174
- @content_mapping = XmlMappingRule.new(
175
- nil,
176
- to: to,
177
- render_nil: render_nil,
178
- render_default: render_default,
179
- render_empty: render_empty,
180
- with: with,
181
- delegate: delegate,
182
- mixed_content: mixed,
183
- cdata: cdata,
184
- value_map: value_map,
185
- )
186
- end
187
-
188
- def map_all(
189
- to:,
190
- render_nil: false,
191
- render_default: false,
192
- delegate: nil,
193
- with: {},
194
- namespace: (namespace_set = false
195
- nil),
196
- prefix: (prefix_set = false
197
- nil),
198
- render_empty: false
199
- )
200
- validate!(
201
- Constants::RAW_MAPPING_KEY,
202
- to,
203
- with,
204
- render_nil,
205
- render_empty,
206
- type: TYPES[:all_content],
207
- )
208
-
209
- rule = XmlMappingRule.new(
210
- Constants::RAW_MAPPING_KEY,
211
- to: to,
212
- render_nil: render_nil,
213
- render_default: render_default,
214
- with: with,
215
- delegate: delegate,
216
- namespace: namespace,
217
- prefix: prefix,
218
- default_namespace: namespace_uri,
219
- namespace_set: namespace_set != false,
220
- prefix_set: prefix_set != false,
221
- )
222
-
223
- @raw_mapping = rule
224
- end
225
-
226
- alias map_all_content map_all
227
-
228
- def sequence(&block)
229
- @element_sequence << Sequence.new(self).tap do |s|
230
- s.instance_eval(&block)
231
- end
232
- end
233
-
234
- def import_model_mappings(model)
235
- raise Lutaml::Model::ImportModelWithRootError.new(model) if model.root?
236
-
237
- mappings = model.mappings_for(:xml)
238
- @elements.merge!(mappings.instance_variable_get(:@elements))
239
- @attributes.merge!(mappings.instance_variable_get(:@attributes))
240
- (@element_sequence << mappings.element_sequence).flatten!
241
- end
242
-
243
- def validate!(key, to, with, render_nil, render_empty, type: nil)
244
- validate_raw_mappings!(type)
245
- validate_to_and_with_arguments!(key, to, with)
246
-
247
- if render_nil == :as_empty || render_empty == :as_empty
248
- raise IncorrectMappingArgumentsError.new(
249
- ":as_empty is not supported for XML mappings",
250
- )
251
- end
252
- end
253
-
254
- def validate_to_and_with_arguments!(key, to, with)
255
- if to.nil? && with.empty?
256
- raise IncorrectMappingArgumentsError.new(
257
- ":to or :with argument is required for mapping '#{key}'",
258
- )
259
- end
260
-
261
- validate_with_options!(key, with)
262
- end
263
-
264
- def validate_with_options!(key, with)
265
- if !with.empty? && (with[:from].nil? || with[:to].nil?)
266
- raise IncorrectMappingArgumentsError.new(
267
- ":with argument for mapping '#{key}' requires :to and :from keys",
268
- )
269
- end
270
- end
271
-
272
- def validate_raw_mappings!(type)
273
- if !@raw_mapping.nil? && type != TYPES[:attribute]
274
- raise StandardError, "#{type} is not allowed, only #{TYPES[:attribute]} " \
275
- "is allowed with #{TYPES[:all_content]}"
276
- end
277
-
278
- if !(elements.empty? && content_mapping.nil?) && type == TYPES[:all_content]
279
- raise StandardError, "#{TYPES[:all_content]} is not allowed with other mappings"
280
- end
281
- end
282
-
283
- def elements
284
- @elements.values
285
- end
286
-
287
- def attributes
288
- @attributes.values
289
- end
290
-
291
- def content_mapping
292
- @content_mapping
293
- end
294
-
295
- def raw_mapping
296
- @raw_mapping
297
- end
298
-
299
- def mappings
300
- elements + attributes + [content_mapping, raw_mapping].compact
301
- end
302
-
303
- def element(name)
304
- elements.detect do |rule|
305
- name == rule.to
306
- end
307
- end
308
-
309
- def attribute(name)
310
- attributes.detect do |rule|
311
- name == rule.to
312
- end
313
- end
314
-
315
- def find_by_name(name)
316
- if ["text", "#cdata-section"].include?(name.to_s)
317
- content_mapping
318
- else
319
- mappings.detect do |rule|
320
- rule.name == name.to_s || rule.name == name.to_sym
321
- end
322
- end
323
- end
324
-
325
- def mapping_attributes_hash
326
- @attributes
327
- end
328
-
329
- def mapping_elements_hash
330
- @elements
331
- end
332
-
333
- def merge_mapping_attributes(mapping)
334
- mapping_attributes_hash.merge!(mapping.mapping_attributes_hash)
335
- end
336
-
337
- def merge_mapping_elements(mapping)
338
- mapping_elements_hash.merge!(mapping.mapping_elements_hash)
339
- end
340
-
341
- def merge_elements_sequence(mapping)
342
- mapping.element_sequence.each do |sequence|
343
- element_sequence << Lutaml::Model::Sequence.new(self).tap do |instance|
344
- sequence.attributes.each do |attr|
345
- instance.attributes << attr.deep_dup
346
- end
347
- end
348
- end
349
- end
350
-
351
- def deep_dup
352
- self.class.new.tap do |xml_mapping|
353
- xml_mapping.root(@root_element.dup, mixed: @mixed_content,
354
- ordered: @ordered)
355
- xml_mapping.namespace(@namespace_uri.dup, @namespace_prefix.dup)
356
-
357
- attributes_to_dup.each do |var_name|
358
- value = instance_variable_get(var_name)
359
- xml_mapping.instance_variable_set(var_name, Utils.deep_dup(value))
360
- end
361
- end
362
- end
363
-
364
- def polymorphic_mapping
365
- mappings.find(&:polymorphic_mapping?)
366
- end
367
-
368
- def attributes_to_dup
369
- @attributes_to_dup ||= %i[
370
- @content_mapping
371
- @raw_mapping
372
- @element_sequence
373
- @attributes
374
- @elements
375
- ]
376
- end
377
-
378
- def dup_mappings(mappings)
379
- new_mappings = {}
380
-
381
- mappings.each do |key, mapping_rule|
382
- new_mappings[key] = mapping_rule.deep_dup
383
- end
384
-
385
- new_mappings
386
- end
387
- end
388
- end
389
- end
@@ -1,139 +0,0 @@
1
- require_relative "mapping_rule"
2
-
3
- module Lutaml
4
- module Model
5
- class XmlMappingRule < MappingRule
6
- attr_reader :namespace, :prefix, :mixed_content, :default_namespace, :cdata
7
-
8
- def initialize(
9
- name,
10
- to:,
11
- render_nil: false,
12
- render_default: false,
13
- render_empty: false,
14
- treat_nil: nil,
15
- treat_empty: nil,
16
- treat_omitted: nil,
17
- with: {},
18
- delegate: nil,
19
- namespace: nil,
20
- prefix: nil,
21
- mixed_content: false,
22
- cdata: false,
23
- namespace_set: false,
24
- prefix_set: false,
25
- attribute: false,
26
- default_namespace: nil,
27
- polymorphic: {},
28
- polymorphic_map: {},
29
- transform: {},
30
- value_map: {}
31
- )
32
- super(
33
- name,
34
- to: to,
35
- render_nil: render_nil,
36
- render_default: render_default,
37
- render_empty: render_empty,
38
- treat_nil: treat_nil,
39
- treat_empty: treat_empty,
40
- treat_omitted: treat_omitted,
41
- with: with,
42
- delegate: delegate,
43
- attribute: attribute,
44
- polymorphic: polymorphic,
45
- polymorphic_map: polymorphic_map,
46
- transform: transform,
47
- value_map: value_map,
48
- )
49
-
50
- @namespace = if namespace.to_s == "inherit"
51
- # we are using inherit_namespace in xml builder by
52
- # default so no need to do anything here.
53
- else
54
- namespace
55
- end
56
- @prefix = prefix
57
- @mixed_content = mixed_content
58
- @cdata = cdata
59
-
60
- @default_namespace = default_namespace
61
-
62
- @namespace_set = namespace_set
63
- @prefix_set = prefix_set
64
- end
65
-
66
- def namespace_set?
67
- !!@namespace_set
68
- end
69
-
70
- def prefix_set?
71
- !!@prefix_set
72
- end
73
-
74
- def content_mapping?
75
- name.nil?
76
- end
77
-
78
- def content_key
79
- cdata ? "#cdata-section" : "text"
80
- end
81
-
82
- def mixed_content?
83
- !!@mixed_content
84
- end
85
-
86
- def prefixed_name
87
- rule_name = multiple_mappings? ? name.first : name
88
- if prefix
89
- "#{prefix}:#{rule_name}"
90
- else
91
- rule_name
92
- end
93
- end
94
-
95
- def namespaced_names(parent_namespace = nil)
96
- if multiple_mappings?
97
- name.map { |rule_name| namespaced_name(parent_namespace, rule_name) }
98
- else
99
- [namespaced_name(parent_namespace)]
100
- end
101
- end
102
-
103
- def namespaced_name(parent_namespace = nil, name = self.name)
104
- if name.to_s == "lang"
105
- "#{prefix}:#{name}"
106
- elsif namespace_set? || @attribute
107
- [namespace, name].compact.join(":")
108
- elsif default_namespace
109
- "#{default_namespace}:#{name}"
110
- else
111
- [parent_namespace, name].compact.join(":")
112
- end
113
- end
114
-
115
- def deep_dup
116
- self.class.new(
117
- name.dup,
118
- to: to,
119
- render_nil: render_nil,
120
- render_default: render_default,
121
- with: Utils.deep_dup(custom_methods),
122
- delegate: delegate,
123
- namespace: namespace.dup,
124
- prefix: prefix.dup,
125
- mixed_content: mixed_content,
126
- cdata: cdata,
127
- namespace_set: namespace_set?,
128
- prefix_set: prefix_set?,
129
- attribute: attribute,
130
- polymorphic: polymorphic.dup,
131
- default_namespace: default_namespace.dup,
132
- transform: transform.dup,
133
- render_empty: render_empty.dup,
134
- value_map: Utils.deep_dup(@value_map),
135
- )
136
- end
137
- end
138
- end
139
- end
@@ -1,17 +0,0 @@
1
- require_relative "key_value_mapping"
2
-
3
- module Lutaml
4
- module Model
5
- class YamlMapping < KeyValueMapping
6
- def initialize
7
- super(:yaml)
8
- end
9
-
10
- def deep_dup
11
- self.class.new.tap do |new_mapping|
12
- new_mapping.instance_variable_set(:@mappings, duplicate_mappings)
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,14 +0,0 @@
1
- module Lutaml
2
- module Model
3
- module Mapping
4
- end
5
- end
6
- end
7
-
8
- require_relative "mapping/mapping_rule"
9
- require_relative "mapping/yaml_mapping"
10
- require_relative "mapping/json_mapping"
11
- require_relative "mapping/toml_mapping"
12
- require_relative "mapping/key_value_mapping_rule"
13
- require_relative "mapping/xml_mapping"
14
- require_relative "mapping/xml_mapping_rule"
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "toml_object"
4
-
5
- module Lutaml
6
- module Model
7
- module TomlAdapter
8
- # Base class for TOML documents
9
- class TomlDocument < TomlObject
10
- def self.parse(toml, _options = {})
11
- raise NotImplementedError, "Subclasses must implement `parse`."
12
- end
13
-
14
- def to_toml(*args)
15
- raise NotImplementedError, "Subclasses must implement `to_toml`."
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Model
5
- module TomlAdapter
6
- # Base class for TOML objects
7
- class TomlObject
8
- attr_reader :attributes
9
-
10
- def initialize(attributes = {})
11
- @attributes = attributes
12
- end
13
-
14
- def [](key)
15
- @attributes[key]
16
- end
17
-
18
- def []=(key, value)
19
- @attributes[key] = value
20
- end
21
-
22
- def to_h
23
- @attributes
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,20 +0,0 @@
1
- require "tomlib"
2
- require_relative "toml_document"
3
-
4
- module Lutaml
5
- module Model
6
- module TomlAdapter
7
- class TomlibAdapter < TomlDocument
8
- def self.parse(toml, _options = {})
9
- data = Tomlib.load(toml)
10
- new(data)
11
- end
12
-
13
- def to_toml(*args)
14
- Tomlib.dump(to_h, *args)
15
- # Tomlib::Generator.new(to_h).toml_str
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,6 +0,0 @@
1
- module Lutaml
2
- module Model
3
- module TomlAdapter
4
- end
5
- end
6
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "yaml_object"
4
-
5
- module Lutaml
6
- module Model
7
- module YamlAdapter
8
- # Base class for YAML documents
9
- class YamlDocument < YamlObject
10
- def self.parse(yaml, _options = {})
11
- raise NotImplementedError, "Subclasses must implement `parse`."
12
- end
13
-
14
- def to_yaml(*args)
15
- raise NotImplementedError, "Subclasses must implement `to_yaml`."
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Model
5
- module YamlAdapter
6
- # Base class for YAML objects
7
- class YamlObject
8
- attr_reader :attributes
9
-
10
- def initialize(attributes = {})
11
- @attributes = attributes
12
- end
13
-
14
- def [](key)
15
- @attributes[key]
16
- end
17
-
18
- def []=(key, value)
19
- @attributes[key] = value
20
- end
21
-
22
- def to_h
23
- @attributes
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Model
5
- module YamlAdapter
6
- end
7
- end
8
- end