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
@@ -228,13 +228,24 @@ RSpec.describe "Group" do
228
228
  )
229
229
  end
230
230
 
231
- it "raises error if root_less class used for deserializing" do
232
- ceramic = GroupSpec::Ceramic.new(type: "Data", name: "Starc")
231
+ context "deserializing XML" do
232
+ let(:ceramic) { GroupSpec::Ceramic.new(type: "Data", name: "Starc") }
233
+
234
+ it "raises error for root_less class" do
235
+ expect { ceramic.to_xml }.to raise_error(
236
+ Lutaml::Model::NoRootMappingError,
237
+ "GroupSpec::Ceramic has `no_root`, it allowed only for reusable models",
238
+ )
239
+ end
240
+ end
233
241
 
234
- expect { ceramic.to_xml }.to raise_error(
235
- Lutaml::Model::NoRootMappingError,
236
- "GroupSpec::Ceramic has `no_root`, it allowed only for reusable models",
237
- )
242
+ context "deserializing key-value formats" do
243
+ let(:ceramic) { GroupSpec::Ceramic.new(type: "Data", name: "Starc") }
244
+
245
+ it "does not raises error for root_less class" do
246
+ expect { ceramic.to_yaml }
247
+ .not_to raise_error(Lutaml::Model::NoRootMappingError)
248
+ end
238
249
  end
239
250
 
240
251
  it "correctly get the element of root-less class" do
@@ -412,7 +423,7 @@ RSpec.describe "Group" do
412
423
  context "with sequence elements" do
413
424
  it "updates sequence elements only in `Mrow`" do
414
425
  sequence = GroupSpec::Mrow.mappings_for(:xml).element_sequence.first
415
- sequence.attributes << Lutaml::Model::XmlMappingRule.new(
426
+ sequence.attributes << Lutaml::Model::Xml::MappingRule.new(
416
427
  "new_element",
417
428
  to: :new_element,
418
429
  namespace: "http://example.com",
@@ -0,0 +1,255 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "HashAdapter" do
4
+ before do
5
+ stub_const("HashMappingSpec", Module.new)
6
+
7
+ simple_class = Class.new(Lutaml::Model::Serializable) do
8
+ attribute :name, :string
9
+ attribute :age, :integer
10
+ attribute :active, :boolean
11
+
12
+ hsh do
13
+ map "name", to: :name
14
+ map "age", to: :age
15
+ map "is_active", to: :active
16
+ end
17
+ end
18
+
19
+ stub_const("HashMappingSpec::SimpleClass", simple_class)
20
+
21
+ nested_class = Class.new(Lutaml::Model::Serializable) do
22
+ attribute :title, :string
23
+ attribute :simple, HashMappingSpec::SimpleClass
24
+ attribute :items, :string, collection: true
25
+
26
+ hsh do
27
+ map "title", to: :title
28
+ map "simple", to: :simple
29
+ map "items", to: :items
30
+ end
31
+ end
32
+
33
+ stub_const("HashMappingSpec::NestedClass", nested_class)
34
+
35
+ collection_class = Class.new(Lutaml::Model::Serializable) do
36
+ attribute :name, :string
37
+ attribute :simples, HashMappingSpec::SimpleClass, collection: true
38
+
39
+ hsh do
40
+ map "name", to: :name
41
+ map "simples", to: :simples
42
+ end
43
+ end
44
+
45
+ stub_const("HashMappingSpec::CollectionClass", collection_class)
46
+ end
47
+
48
+ describe "from_hash" do
49
+ context "with simple attributes" do
50
+ let(:parsed) do
51
+ HashMappingSpec::SimpleClass.from_hash(hash_data)
52
+ end
53
+
54
+ let(:hash_data) do
55
+ {
56
+ "name" => "John Doe",
57
+ "age" => 30,
58
+ "is_active" => true,
59
+ }
60
+ end
61
+
62
+ let(:expected) do
63
+ HashMappingSpec::SimpleClass.new(
64
+ name: "John Doe",
65
+ age: 30,
66
+ active: true,
67
+ )
68
+ end
69
+
70
+ it "deserializes hash to object" do
71
+ expect(parsed).to eq(expected)
72
+ end
73
+ end
74
+
75
+ context "with nested objects" do
76
+ let(:parsed) do
77
+ HashMappingSpec::NestedClass.from_hash(hash_data)
78
+ end
79
+
80
+ let(:hash_data) do
81
+ {
82
+ "title" => "Test Title",
83
+ "simple" => {
84
+ "name" => "Jane Doe",
85
+ "age" => 25,
86
+ "is_active" => false,
87
+ },
88
+ "items" => ["item1", "item2", "item3"],
89
+ }
90
+ end
91
+
92
+ let(:expected) do
93
+ HashMappingSpec::NestedClass.new(
94
+ title: "Test Title",
95
+ simple: HashMappingSpec::SimpleClass.new(
96
+ name: "Jane Doe",
97
+ age: 25,
98
+ active: false,
99
+ ),
100
+ items: ["item1", "item2", "item3"],
101
+ )
102
+ end
103
+
104
+ it "deserializes nested objects" do
105
+ expect(parsed).to eq(expected)
106
+ end
107
+ end
108
+
109
+ context "with collections of objects" do
110
+ let(:parsed) do
111
+ HashMappingSpec::CollectionClass.from_hash(hash_data)
112
+ end
113
+
114
+ let(:hash_data) do
115
+ {
116
+ "name" => "Collection",
117
+ "simples" => [
118
+ { "name" => "First", "age" => 10, "is_active" => true },
119
+ { "name" => "Second", "age" => 20, "is_active" => false },
120
+ ],
121
+ }
122
+ end
123
+
124
+ let(:expected) do
125
+ HashMappingSpec::CollectionClass.new(
126
+ name: "Collection",
127
+ simples: [
128
+ HashMappingSpec::SimpleClass.new(
129
+ name: "First",
130
+ age: 10,
131
+ active: true,
132
+ ),
133
+ HashMappingSpec::SimpleClass.new(
134
+ name: "Second",
135
+ age: 20,
136
+ active: false,
137
+ ),
138
+ ],
139
+ )
140
+ end
141
+
142
+ it "deserializes collections of objects" do
143
+ expect(parsed).to eq(expected)
144
+ end
145
+ end
146
+ end
147
+
148
+ describe "to_hash" do
149
+ context "with simple attributes" do
150
+ let(:instance) do
151
+ HashMappingSpec::SimpleClass.new(
152
+ name: "John Doe",
153
+ age: 30,
154
+ active: true,
155
+ )
156
+ end
157
+
158
+ let(:expected_hash) do
159
+ {
160
+ "name" => "John Doe",
161
+ "age" => 30,
162
+ "is_active" => true,
163
+ }
164
+ end
165
+
166
+ it "serializes object to hash" do
167
+ expect(instance.to_hash).to eq(expected_hash)
168
+ end
169
+ end
170
+
171
+ context "with nested objects" do
172
+ let(:simple) do
173
+ HashMappingSpec::SimpleClass.new(
174
+ name: "Jane Doe",
175
+ age: 25,
176
+ active: false,
177
+ )
178
+ end
179
+
180
+ let(:instance) do
181
+ HashMappingSpec::NestedClass.new(
182
+ title: "Test Title",
183
+ simple: simple,
184
+ items: ["item1", "item2", "item3"],
185
+ )
186
+ end
187
+
188
+ let(:expected_hash) do
189
+ {
190
+ "title" => "Test Title",
191
+ "simple" => {
192
+ "name" => "Jane Doe",
193
+ "age" => 25,
194
+ "is_active" => false,
195
+ },
196
+ "items" => ["item1", "item2", "item3"],
197
+ }
198
+ end
199
+
200
+ it "serializes nested objects to hash" do
201
+ expect(instance.to_hash).to eq(expected_hash)
202
+ end
203
+ end
204
+
205
+ context "with collections of objects" do
206
+ let(:simples) do
207
+ [
208
+ HashMappingSpec::SimpleClass.new(name: "First", age: 10, active: true),
209
+ HashMappingSpec::SimpleClass.new(name: "Second", age: 20, active: false),
210
+ ]
211
+ end
212
+
213
+ let(:instance) do
214
+ HashMappingSpec::CollectionClass.new(
215
+ name: "Collection",
216
+ simples: simples,
217
+ )
218
+ end
219
+
220
+ let(:expected_hash) do
221
+ {
222
+ "name" => "Collection",
223
+ "simples" => [
224
+ { "name" => "First", "age" => 10, "is_active" => true },
225
+ { "name" => "Second", "age" => 20, "is_active" => false },
226
+ ],
227
+ }
228
+ end
229
+
230
+ it "serializes collections of objects to hash" do
231
+ expect(instance.to_hash).to eq(expected_hash)
232
+ end
233
+ end
234
+ end
235
+
236
+ describe "round-trip serialization" do
237
+ let(:original_hash) do
238
+ {
239
+ "name" => "Collection",
240
+ "simples" => [
241
+ { "name" => "First", "age" => 10, "is_active" => true },
242
+ { "name" => "Second", "age" => 20, "is_active" => false },
243
+ ],
244
+ }
245
+ end
246
+
247
+ let(:parsed) do
248
+ HashMappingSpec::CollectionClass.from_hash(original_hash)
249
+ end
250
+
251
+ it "maintains data integrity through serialization and deserialization" do
252
+ expect(parsed.to_hash).to eq(original_hash)
253
+ end
254
+ end
255
+ end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
- require "lutaml/model/json_adapter/standard_json_adapter"
3
- require "lutaml/model/json_adapter/multi_json_adapter"
2
+ require "lutaml/model/json/standard_adapter"
3
+ require "lutaml/model/json/multi_json_adapter"
4
4
  require_relative "../../fixtures/sample_model"
5
5
 
6
6
  RSpec.describe "JsonAdapter" do
@@ -9,9 +9,9 @@ RSpec.describe "JsonAdapter" do
9
9
  let(:model) { SampleModel.new(attributes) }
10
10
 
11
11
  let(:expected_json) do
12
- if adapter_class == Lutaml::Model::JsonAdapter::StandardJsonAdapter
12
+ if adapter_class == Lutaml::Model::Json::StandardAdapter
13
13
  JSON.generate(attributes)
14
- elsif adapter_class == Lutaml::Model::JsonAdapter::MultiJsonAdapter
14
+ elsif adapter_class == Lutaml::Model::Json::MultiJsonAdapter
15
15
  MultiJson.dump(attributes)
16
16
  end
17
17
  end
@@ -29,11 +29,11 @@ RSpec.describe "JsonAdapter" do
29
29
  end
30
30
  end
31
31
 
32
- describe Lutaml::Model::JsonAdapter::StandardJsonAdapter do
32
+ describe Lutaml::Model::Json::StandardAdapter do
33
33
  it_behaves_like "a JSON adapter", described_class
34
34
  end
35
35
 
36
- describe Lutaml::Model::JsonAdapter::MultiJsonAdapter do
36
+ describe Lutaml::Model::Json::MultiJsonAdapter do
37
37
  it_behaves_like "a JSON adapter", described_class
38
38
  end
39
39
  end
@@ -3,6 +3,30 @@ require "spec_helper"
3
3
  RSpec.describe Lutaml::Model::KeyValueMapping do
4
4
  let(:mapping) { described_class.new(:json) }
5
5
 
6
+ it "raises error when :to is nil and :with single mapping" do
7
+ expect do
8
+ mapping.map("test", with: { from: :from_method })
9
+ end.to raise_error(
10
+ Lutaml::Model::IncorrectMappingArgumentsError,
11
+ ":with argument for mapping 'test' requires :to and :from keys",
12
+ )
13
+ end
14
+
15
+ it "raises error when :to is nil and :with arguments have nil values" do
16
+ expect do
17
+ mapping.map("test", with: { from: nil, to: nil })
18
+ end.to raise_error(
19
+ Lutaml::Model::IncorrectMappingArgumentsError,
20
+ ":with argument for mapping 'test' requires :to and :from keys",
21
+ )
22
+ end
23
+
24
+ it "does not raise error when using :to, and :with has single mapping" do
25
+ expect do
26
+ mapping.map("test", to: :field, with: { to: :to_method })
27
+ end.not_to raise_error
28
+ end
29
+
6
30
  context "with delegate option" do
7
31
  before do
8
32
  mapping.map("type", to: :type, delegate: :some_delegate)
@@ -115,7 +139,7 @@ RSpec.describe Lutaml::Model::KeyValueMapping do
115
139
  end
116
140
 
117
141
  context "with TOML format" do
118
- let(:mapping) { Lutaml::Model::TomlMapping.new }
142
+ let(:mapping) { Lutaml::Model::Toml::Mapping.new }
119
143
 
120
144
  it "raises error when render_nil is :as_nil" do
121
145
  expect do
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "spec_helper"
4
4
  require "lutaml/model"
5
- require "lutaml/model/xml_adapter/nokogiri_adapter"
6
- require "lutaml/model/xml_adapter/ox_adapter"
7
- require "lutaml/model/xml_adapter/oga_adapter"
5
+ require "lutaml/model/xml/nokogiri_adapter"
6
+ require "lutaml/model/xml/ox_adapter"
7
+ require "lutaml/model/xml/oga_adapter"
8
8
  require_relative "../../fixtures/sample_model"
9
9
 
10
10
  module MixedContentSpec
@@ -246,7 +246,7 @@ RSpec.describe "MixedContent" do
246
246
 
247
247
  # due to the difference in capturing
248
248
  # newlines in ox and nokogiri adapters
249
- if adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
249
+ if adapter_class == Lutaml::Model::Xml::OxAdapter
250
250
  expected_output = expected_output.gsub(/\n\s*/, " ")
251
251
  end
252
252
 
@@ -297,7 +297,7 @@ RSpec.describe "MixedContent" do
297
297
 
298
298
  # due to the difference in capturing
299
299
  # newlines in ox and nokogiri adapters
300
- if adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
300
+ if adapter_class == Lutaml::Model::Xml::OxAdapter
301
301
  expected_output = expected_output.gsub(/\n\s*/, " ")
302
302
  end
303
303
 
@@ -353,7 +353,7 @@ RSpec.describe "MixedContent" do
353
353
 
354
354
  # due to the difference in capturing
355
355
  # newlines in ox and nokogiri adapters
356
- if adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
356
+ if adapter_class == Lutaml::Model::Xml::OxAdapter
357
357
  expected_output = expected_output.gsub(/\n\s*/, " ")
358
358
  end
359
359
 
@@ -412,7 +412,7 @@ RSpec.describe "MixedContent" do
412
412
 
413
413
  # due to the difference in capturing
414
414
  # newlines in ox and nokogiri adapters
415
- if adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
415
+ if adapter_class == Lutaml::Model::Xml::OxAdapter
416
416
  expected_output = expected_output.gsub(/\n\s*/, " ")
417
417
  end
418
418
 
@@ -539,7 +539,7 @@ RSpec.describe "MixedContent" do
539
539
  it "deserializes special char mixed content correctly" do
540
540
  parsed = MixedContentSpec::SpecialCharContentWithRawAndMixedOption.from_xml(xml)
541
541
  expected_content = public_send(:"expected_#{adapter_class.type}_content")
542
- parsed.special.force_encoding("UTF-8") unless adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
542
+ parsed.special.force_encoding("UTF-8") unless adapter_class == Lutaml::Model::Xml::NokogiriAdapter
543
543
 
544
544
  expect(parsed.special.strip).to eq(expected_content)
545
545
  end
@@ -608,7 +608,7 @@ RSpec.describe "MixedContent" do
608
608
  it "deserializes special char mixed content correctly" do
609
609
  parsed = MixedContentSpec::SpecialCharContentWithRawAndMixedOption.from_xml(xml)
610
610
 
611
- expected_output = adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter ? expected_nokogiri_content : expected_ox_content
611
+ expected_output = adapter_class == Lutaml::Model::Xml::NokogiriAdapter ? expected_nokogiri_content : expected_ox_content
612
612
  expect(parsed.special.strip).to eq(expected_output)
613
613
  end
614
614
  end
@@ -715,9 +715,9 @@ RSpec.describe "MixedContent" do
715
715
  parsed = MixedContentSpec::HexCode.from_xml(xml, encoding: nil)
716
716
  serialized = parsed.to_xml(encoding: nil)
717
717
 
718
- expected_output = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
718
+ expected_output = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
719
719
  expected_encoding_nil_nokogiri_xml
720
- elsif adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
720
+ elsif adapter_class == Lutaml::Model::Xml::OxAdapter
721
721
  expected_encoding_nil_ox_xml
722
722
  else
723
723
  expected_encoding_nil_oga_xml
@@ -726,7 +726,7 @@ RSpec.describe "MixedContent" do
726
726
  expect(parsed.encoding).to be_nil
727
727
  expect(serialized.strip).to include(expected_output.strip)
728
728
 
729
- if adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
729
+ if adapter_class == Lutaml::Model::Xml::OxAdapter
730
730
  expect(serialized.encoding.to_s).to eq("ASCII-8BIT")
731
731
  else
732
732
  expect(serialized.encoding.to_s).to eq("UTF-8")
@@ -750,7 +750,7 @@ RSpec.describe "MixedContent" do
750
750
  it "deserializes SHIFT encoded content correctly with explicit encoding option" do
751
751
  parsed = MixedContentSpec::Shift.from_xml(fixture, encoding: "Shift_JIS")
752
752
 
753
- expected_content = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
753
+ expected_content = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
754
754
  "手書き英字1"
755
755
  else
756
756
  "\x8E\xE8\x8F\x91\x82\xAB\x89p\x8E\x9A\x82P".force_encoding("Shift_JIS")
@@ -762,7 +762,7 @@ RSpec.describe "MixedContent" do
762
762
  it "deserializes SHIFT encoded content incorrectly without explicit encoding option" do
763
763
  parsed = MixedContentSpec::Shift.from_xml(fixture)
764
764
 
765
- expected_content = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
765
+ expected_content = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
766
766
  "手書き英字1"
767
767
  else
768
768
  "\x8E\xE8\x8F\x91\x82\xAB\x89p\x8E\x9A\x82P".force_encoding("Shift_JIS")
@@ -785,7 +785,7 @@ RSpec.describe "MixedContent" do
785
785
  parsed = MixedContentSpec::Shift.from_xml(fixture, encoding: "Shift_JIS")
786
786
  serialized = parsed.to_xml(encoding: "UTF-8")
787
787
 
788
- parsed_xml = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
788
+ parsed_xml = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
789
789
  "手書き英字1"
790
790
  else
791
791
  "\x8E\xE8\x8F\x91\x82\xAB\x89p\x8E\x9A\x82P".force_encoding("Shift_JIS")
@@ -802,7 +802,7 @@ RSpec.describe "MixedContent" do
802
802
  parsed = MixedContentSpec::Shift.from_xml(fixture, encoding: "Shift_JIS")
803
803
  serialized = parsed.to_xml(encoding: "Shift_JIS")
804
804
 
805
- expected_xml = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
805
+ expected_xml = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
806
806
  "手書き英字1"
807
807
  else
808
808
  "\x8E\xE8\x8F\x91\x82\xAB\x89p\x8E\x9A\x82P".force_encoding("Shift_JIS")
@@ -829,9 +829,9 @@ RSpec.describe "MixedContent" do
829
829
  parsed = MixedContentSpec::Shift.from_xml(fixture)
830
830
  serialized = parsed.to_xml(encoding: "Shift_JIS")
831
831
 
832
- expected_content = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
832
+ expected_content = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
833
833
  "<root>\n <FieldName>手書き英字1</FieldName>\n <FieldName>123456</FieldName>\n</root>".encode("Shift_JIS")
834
- elsif adapter_class == Lutaml::Model::XmlAdapter::OxAdapter
834
+ elsif adapter_class == Lutaml::Model::Xml::OxAdapter
835
835
  "<root>\n <FieldName>手書き英字1</FieldName>\n <FieldName>123456</FieldName>\n</root>\n".encode("Shift_JIS")
836
836
  else
837
837
  "<root><FieldName>手書き英字1</FieldName><FieldName>123456</FieldName></root>".encode("Shift_JIS")
@@ -868,7 +868,7 @@ RSpec.describe "MixedContent" do
868
868
  it "deserializes latin encoded content correctly" do
869
869
  parsed = MixedContentSpec::Latin.from_xml(fixture, encoding: "ISO-8859-1")
870
870
 
871
- expected_content = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
871
+ expected_content = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
872
872
  ["Müller", "José"]
873
873
  else
874
874
  ["M\xFCller".force_encoding("ISO-8859-1"), "Jos\xE9".force_encoding("ISO-8859-1")]
@@ -882,7 +882,7 @@ RSpec.describe "MixedContent" do
882
882
  it "deserializes latin encoded content correctly, bcz xml.encoding used for parsing" do
883
883
  parsed = MixedContentSpec::Latin.from_xml(fixture)
884
884
 
885
- expected_content = if adapter_class == Lutaml::Model::XmlAdapter::NokogiriAdapter
885
+ expected_content = if adapter_class == Lutaml::Model::Xml::NokogiriAdapter
886
886
  ["Müller", "José"]
887
887
  else
888
888
  ["M\xFCller".force_encoding("ISO-8859-1"), "Jos\xE9".force_encoding("ISO-8859-1")]
@@ -898,7 +898,7 @@ RSpec.describe "MixedContent" do
898
898
  it "serializes latin encoded content correctly" do
899
899
  parsed = MixedContentSpec::Latin.from_xml(fixture, encoding: "ISO-8859-1")
900
900
  serialized = parsed.to_xml
901
- expected_xml = if adapter_class == Lutaml::Model::XmlAdapter::OgaAdapter
901
+ expected_xml = if adapter_class == Lutaml::Model::Xml::OgaAdapter
902
902
  "<note><to>Jos\xE9</to><from>M\xFCller</from><heading>Reminder</heading></note>"
903
903
  else
904
904
  "<note>\n <to>Jos\xE9</to>\n <from>M\xFCller</from>\n <heading>Reminder</heading>\n</note>"
@@ -910,7 +910,7 @@ RSpec.describe "MixedContent" do
910
910
  end
911
911
  end
912
912
 
913
- describe Lutaml::Model::XmlAdapter::NokogiriAdapter do
913
+ describe Lutaml::Model::Xml::NokogiriAdapter do
914
914
  it_behaves_like "mixed content behavior", described_class
915
915
 
916
916
  it "raises error when serializes special char content with false encoding: 'ABC'" do
@@ -920,11 +920,11 @@ RSpec.describe "MixedContent" do
920
920
  end
921
921
  end
922
922
 
923
- describe Lutaml::Model::XmlAdapter::OxAdapter do
923
+ describe Lutaml::Model::Xml::OxAdapter do
924
924
  it_behaves_like "mixed content behavior", described_class
925
925
  end
926
926
 
927
- describe Lutaml::Model::XmlAdapter::OgaAdapter do
927
+ describe Lutaml::Model::Xml::OgaAdapter do
928
928
  it_behaves_like "mixed content behavior", described_class
929
929
  end
930
930
  end
@@ -252,11 +252,11 @@ RSpec.describe MultipleMapping do
252
252
  end
253
253
 
254
254
  context "with Nokogiri adapter" do
255
- it_behaves_like "xml adapter with multiple mappings", Lutaml::Model::XmlAdapter::NokogiriAdapter
255
+ it_behaves_like "xml adapter with multiple mappings", Lutaml::Model::Xml::NokogiriAdapter
256
256
  end
257
257
 
258
258
  context "with Ox adapter" do
259
- it_behaves_like "xml adapter with multiple mappings", Lutaml::Model::XmlAdapter::OxAdapter
259
+ it_behaves_like "xml adapter with multiple mappings", Lutaml::Model::Xml::OxAdapter
260
260
  end
261
261
  end
262
262
 
@@ -285,7 +285,7 @@ RSpec.describe MultipleMapping do
285
285
  context "with XML format" do
286
286
  shared_examples "xml adapter with custom methods" do |_adapter_class|
287
287
  before do
288
- Lutaml::Model::Config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
288
+ Lutaml::Model::Config.xml_adapter = Lutaml::Model::Xml::NokogiriAdapter
289
289
  end
290
290
 
291
291
  let(:xml_with_alternate) do
@@ -330,11 +330,11 @@ RSpec.describe MultipleMapping do
330
330
  end
331
331
 
332
332
  context "with Nokogiri adapter" do
333
- it_behaves_like "xml adapter with custom methods", Lutaml::Model::XmlAdapter::NokogiriAdapter
333
+ it_behaves_like "xml adapter with custom methods", Lutaml::Model::Xml::NokogiriAdapter
334
334
  end
335
335
 
336
336
  context "with Ox adapter" do
337
- it_behaves_like "xml adapter with custom methods", Lutaml::Model::XmlAdapter::OxAdapter
337
+ it_behaves_like "xml adapter with custom methods", Lutaml::Model::Xml::OxAdapter
338
338
  end
339
339
  end
340
340
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  require "spec_helper"
4
4
  require "lutaml/model"
5
- require "lutaml/model/xml_adapter/nokogiri_adapter"
6
- require "lutaml/model/xml_adapter/ox_adapter"
7
- require "lutaml/model/xml_adapter/oga_adapter"
5
+ require "lutaml/model/xml/nokogiri_adapter"
6
+ require "lutaml/model/xml/ox_adapter"
7
+ require "lutaml/model/xml/oga_adapter"
8
8
  require_relative "../../fixtures/sample_model"
9
9
 
10
10
  module OrderedContentSpec
@@ -69,15 +69,15 @@ RSpec.describe "OrderedContent" do
69
69
  end
70
70
  end
71
71
 
72
- describe Lutaml::Model::XmlAdapter::NokogiriAdapter do
72
+ describe Lutaml::Model::Xml::NokogiriAdapter do
73
73
  it_behaves_like "ordered content behavior", described_class
74
74
  end
75
75
 
76
- describe Lutaml::Model::XmlAdapter::OxAdapter do
76
+ describe Lutaml::Model::Xml::OxAdapter do
77
77
  it_behaves_like "ordered content behavior", described_class
78
78
  end
79
79
 
80
- describe Lutaml::Model::XmlAdapter::OgaAdapter do
80
+ describe Lutaml::Model::Xml::OgaAdapter do
81
81
  it_behaves_like "ordered content behavior", described_class
82
82
  end
83
83
  end