lutaml-model 0.3.23 → 0.3.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +35 -16
  3. data/README.adoc +274 -28
  4. data/lib/lutaml/model/attribute.rb +18 -8
  5. data/lib/lutaml/model/error/type_error.rb +9 -0
  6. data/lib/lutaml/model/error/unknown_type_error.rb +9 -0
  7. data/lib/lutaml/model/error/validation_error.rb +0 -1
  8. data/lib/lutaml/model/error.rb +2 -0
  9. data/lib/lutaml/model/serialize.rb +7 -2
  10. data/lib/lutaml/model/type/boolean.rb +38 -0
  11. data/lib/lutaml/model/type/date.rb +35 -0
  12. data/lib/lutaml/model/type/date_time.rb +32 -4
  13. data/lib/lutaml/model/type/decimal.rb +42 -0
  14. data/lib/lutaml/model/type/float.rb +37 -0
  15. data/lib/lutaml/model/type/hash.rb +62 -0
  16. data/lib/lutaml/model/type/integer.rb +41 -0
  17. data/lib/lutaml/model/type/string.rb +49 -0
  18. data/lib/lutaml/model/type/time.rb +49 -0
  19. data/lib/lutaml/model/type/time_without_date.rb +37 -5
  20. data/lib/lutaml/model/type/value.rb +52 -0
  21. data/lib/lutaml/model/type.rb +50 -114
  22. data/lib/lutaml/model/version.rb +1 -1
  23. data/lib/lutaml/model/xml_adapter/builder/nokogiri.rb +5 -2
  24. data/lib/lutaml/model/xml_adapter/ox_adapter.rb +2 -1
  25. data/lib/lutaml/model/xml_adapter/xml_document.rb +0 -2
  26. data/lutaml-model.gemspec +1 -1
  27. data/spec/address_spec.rb +170 -0
  28. data/spec/fixtures/address.rb +33 -0
  29. data/spec/fixtures/person.rb +73 -0
  30. data/spec/fixtures/sample_model.rb +40 -0
  31. data/spec/fixtures/vase.rb +38 -0
  32. data/spec/fixtures/xml/special_char.xml +13 -0
  33. data/spec/lutaml/model/attribute_spec.rb +112 -0
  34. data/spec/lutaml/model/collection_spec.rb +299 -0
  35. data/spec/lutaml/model/comparable_model_spec.rb +106 -0
  36. data/spec/lutaml/model/custom_model_spec.rb +410 -0
  37. data/spec/lutaml/model/custom_serialization_spec.rb +170 -0
  38. data/spec/lutaml/model/defaults_spec.rb +221 -0
  39. data/spec/lutaml/model/delegation_spec.rb +340 -0
  40. data/spec/lutaml/model/inheritance_spec.rb +92 -0
  41. data/spec/lutaml/model/json_adapter_spec.rb +37 -0
  42. data/spec/lutaml/model/key_value_mapping_spec.rb +86 -0
  43. data/spec/lutaml/model/map_content_spec.rb +118 -0
  44. data/spec/lutaml/model/mixed_content_spec.rb +625 -0
  45. data/spec/lutaml/model/namespace_spec.rb +57 -0
  46. data/spec/lutaml/model/ordered_content_spec.rb +83 -0
  47. data/spec/lutaml/model/render_nil_spec.rb +138 -0
  48. data/spec/lutaml/model/schema/json_schema_spec.rb +79 -0
  49. data/spec/lutaml/model/schema/relaxng_schema_spec.rb +60 -0
  50. data/spec/lutaml/model/schema/xsd_schema_spec.rb +55 -0
  51. data/spec/lutaml/model/schema/yaml_schema_spec.rb +47 -0
  52. data/spec/lutaml/model/serializable_spec.rb +297 -0
  53. data/spec/lutaml/model/serializable_validation_spec.rb +85 -0
  54. data/spec/lutaml/model/simple_model_spec.rb +314 -0
  55. data/spec/lutaml/model/toml_adapter_spec.rb +39 -0
  56. data/spec/lutaml/model/type/boolean_spec.rb +54 -0
  57. data/spec/lutaml/model/type/date_spec.rb +118 -0
  58. data/spec/lutaml/model/type/date_time_spec.rb +127 -0
  59. data/spec/lutaml/model/type/decimal_spec.rb +125 -0
  60. data/spec/lutaml/model/type/float_spec.rb +191 -0
  61. data/spec/lutaml/model/type/hash_spec.rb +63 -0
  62. data/spec/lutaml/model/type/integer_spec.rb +145 -0
  63. data/spec/lutaml/model/type/string_spec.rb +150 -0
  64. data/spec/lutaml/model/type/time_spec.rb +142 -0
  65. data/spec/lutaml/model/type/time_without_date_spec.rb +125 -0
  66. data/spec/lutaml/model/type_spec.rb +276 -0
  67. data/spec/lutaml/model/utils_spec.rb +79 -0
  68. data/spec/lutaml/model/validation_spec.rb +83 -0
  69. data/spec/lutaml/model/with_child_mapping_spec.rb +174 -0
  70. data/spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb +56 -0
  71. data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +56 -0
  72. data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +61 -0
  73. data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +251 -0
  74. data/spec/lutaml/model/xml_adapter_spec.rb +178 -0
  75. data/spec/lutaml/model/xml_mapping_spec.rb +863 -0
  76. data/spec/lutaml/model/yaml_adapter_spec.rb +30 -0
  77. data/spec/lutaml/model_spec.rb +1 -0
  78. data/spec/person_spec.rb +161 -0
  79. data/spec/spec_helper.rb +33 -0
  80. metadata +66 -2
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+ require "lutaml/model/yaml_adapter"
3
+ require_relative "../../fixtures/sample_model"
4
+
5
+ RSpec.shared_examples "a YAML adapter" do |adapter_class|
6
+ let(:attributes) { { "name" => "John Doe", "age" => 30 } }
7
+ let(:model) { SampleModel.new(attributes) }
8
+
9
+ let(:expected_yaml) do
10
+ if adapter_class == Lutaml::Model::YamlAdapter::StandardYamlAdapter
11
+ attributes.to_yaml
12
+ end
13
+ end
14
+
15
+ it "serializes to YAML" do
16
+ yaml = adapter_class.new(attributes).to_yaml
17
+
18
+ expect(yaml).to eq(expected_yaml)
19
+ end
20
+
21
+ it "deserializes from YAML" do
22
+ new_model = adapter_class.parse(expected_yaml)
23
+ expect(new_model["name"]).to eq("John Doe")
24
+ expect(new_model["age"]).to eq(30)
25
+ end
26
+ end
27
+
28
+ RSpec.describe Lutaml::Model::YamlAdapter::StandardYamlAdapter do
29
+ it_behaves_like "a YAML adapter", described_class
30
+ end
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -0,0 +1,161 @@
1
+ require "spec_helper"
2
+ require_relative "fixtures/person"
3
+
4
+ RSpec.describe Person do
5
+ let(:attributes) do
6
+ {
7
+ first_name: "John",
8
+ last_name: "Doe",
9
+ age: 30,
10
+ height: 5.9,
11
+ birthdate: "1990-01-01",
12
+ last_login: "2023-06-08T10:00:00+00:00",
13
+ wakeup_time: "07:00:00",
14
+ active: true,
15
+ }
16
+ end
17
+
18
+ let(:model) { described_class.new(attributes) }
19
+
20
+ let(:attributes_yaml) do
21
+ {
22
+ "firstName" => "John",
23
+ "lastName" => "Doe",
24
+ "age" => 30,
25
+ "height" => 5.9,
26
+ "birthdate" => "1990-01-01",
27
+ "lastLogin" => "2023-06-08T10:00:00+00:00",
28
+ "wakeupTime" => "07:00:00",
29
+ "active" => true,
30
+ }
31
+ end
32
+ let(:attributes_json) do
33
+ {
34
+ firstName: "John",
35
+ lastName: "Doe",
36
+ age: 30,
37
+ height: 5.9,
38
+ birthdate: "1990-01-01",
39
+ lastLogin: "2023-06-08T10:00:00+00:00",
40
+ wakeupTime: "07:00:00",
41
+ active: true,
42
+ }
43
+ end
44
+
45
+ it "serializes to XML" do
46
+ expected_xml = <<~XML
47
+ <p:Person xmlns:p="http://example.com/person" xmlns:nsp1="http://example.com/nsp1">
48
+ <nsp1:FirstName>John</nsp1:FirstName>
49
+ <nsp1:LastName>Doe</nsp1:LastName>
50
+ <p:Age>30</p:Age>
51
+ <p:Height>5.9</p:Height>
52
+ <p:Birthdate>1990-01-01</p:Birthdate>
53
+ <p:LastLogin>2023-06-08T10:00:00+00:00</p:LastLogin>
54
+ <p:WakeupTime>07:00:00</p:WakeupTime>
55
+ <p:Active>true</p:Active>
56
+ </p:Person>
57
+ XML
58
+
59
+ expect(model.to_xml).to be_equivalent_to(expected_xml)
60
+ end
61
+
62
+ it "deserializes from XML" do
63
+ xml = <<~XML
64
+ <p:Person xmlns:p="http://example.com/person" xmlns:nsp1="http://example.com/nsp1">
65
+ <nsp1:FirstName>John</nsp1:FirstName>
66
+ <nsp1:LastName>Doe</nsp1:LastName>
67
+ <p:Age>30</p:Age>
68
+ <p:Height>5.9</p:Height>
69
+ <p:Birthdate>1990-01-01</p:Birthdate>
70
+ <p:LastLogin>2023-06-08T10:00:00+00:00</p:LastLogin>
71
+ <p:WakeupTime>07:00:00</p:WakeupTime>
72
+ <p:Active>true</p:Active>
73
+ </p:Person>
74
+ XML
75
+
76
+ person = described_class.from_xml(xml)
77
+ expect(person.first_name).to eq("John")
78
+ expect(person.age).to eq(30)
79
+ expect(person.height).to eq(5.9)
80
+ expect(person.birthdate).to eq(Date.parse("1990-01-01"))
81
+ expect(person.last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
82
+ expect(person.wakeup_time).to eq(Time.parse("07:00:00"))
83
+ expect(person.active).to be true
84
+ end
85
+
86
+ it "serializes to JSON" do
87
+ expect(model.to_json).to eq(attributes_json.to_json)
88
+ end
89
+
90
+ it "deserializes from JSON" do
91
+ json = attributes_json.to_json
92
+ person = described_class.from_json(json)
93
+ expect(person.first_name).to eq("John")
94
+ expect(person.age).to eq(30)
95
+ expect(person.height).to eq(5.9)
96
+ expect(person.birthdate).to eq(Date.parse("1990-01-01"))
97
+ expect(person.last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
98
+ expect(person.wakeup_time).to eq(Time.parse("07:00:00"))
99
+ expect(person.active).to be true
100
+ end
101
+
102
+ it "deserializes from JSON array" do
103
+ json = [attributes_json.dup, attributes_json.dup].to_json
104
+
105
+ persons = described_class.from_json(json)
106
+
107
+ expect(persons[0].first_name).to eq("John")
108
+ expect(persons[0].age).to eq(30)
109
+ expect(persons[0].height).to eq(5.9)
110
+ expect(persons[0].birthdate).to eq(Date.parse("1990-01-01"))
111
+ expect(persons[0].last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
112
+ expect(persons[0].wakeup_time).to eq(Time.parse("07:00:00"))
113
+ expect(persons[0].active).to be true
114
+
115
+ expect(persons[1].first_name).to eq("John")
116
+ expect(persons[1].age).to eq(30)
117
+ expect(persons[1].height).to eq(5.9)
118
+ expect(persons[1].birthdate).to eq(Date.parse("1990-01-01"))
119
+ expect(persons[1].last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
120
+ expect(persons[1].wakeup_time).to eq(Time.parse("07:00:00"))
121
+ expect(persons[1].active).to be true
122
+ end
123
+
124
+ it "serializes to YAML" do
125
+ expect(model.to_yaml).to eq(attributes_yaml.to_yaml)
126
+ end
127
+
128
+ it "deserializes from YAML" do
129
+ yaml = attributes_yaml.to_yaml
130
+ person = described_class.from_yaml(yaml)
131
+ expect(person.first_name).to eq("John")
132
+ expect(person.age).to eq(30)
133
+ expect(person.height).to eq(5.9)
134
+ expect(person.birthdate).to eq(Date.parse("1990-01-01"))
135
+ expect(person.last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
136
+ expect(person.wakeup_time).to eq(Time.parse("07:00:00"))
137
+ expect(person.active).to be true
138
+ end
139
+
140
+ it "deserializes from YAML array" do
141
+ yaml = [attributes_yaml.dup, attributes_yaml.dup].to_yaml
142
+
143
+ persons = described_class.from_yaml(yaml)
144
+
145
+ expect(persons[0].first_name).to eq("John")
146
+ expect(persons[0].age).to eq(30)
147
+ expect(persons[0].height).to eq(5.9)
148
+ expect(persons[0].birthdate).to eq(Date.parse("1990-01-01"))
149
+ expect(persons[0].last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
150
+ expect(persons[0].wakeup_time).to eq(Time.parse("07:00:00"))
151
+ expect(persons[0].active).to be true
152
+
153
+ expect(persons[1].first_name).to eq("John")
154
+ expect(persons[1].age).to eq(30)
155
+ expect(persons[1].height).to eq(5.9)
156
+ expect(persons[1].birthdate).to eq(Date.parse("1990-01-01"))
157
+ expect(persons[1].last_login).to eq(DateTime.parse("2023-06-08T10:00:00+00:00"))
158
+ expect(persons[1].wakeup_time).to eq(Time.parse("07:00:00"))
159
+ expect(persons[1].active).to be true
160
+ end
161
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/matchers"
4
+ require "equivalent-xml"
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = ".rspec_status"
9
+
10
+ # Disable RSpec exposing methods globally on `Module` and `main`
11
+ config.disable_monkey_patching!
12
+
13
+ config.expect_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+
17
+ def fixture_path(filename)
18
+ File.expand_path("../fixtures/#{filename}", __FILE__)
19
+ end
20
+ end
21
+
22
+ # configuration example
23
+ require_relative "../lib/lutaml/model"
24
+ require_relative "../lib/lutaml/model/xml_adapter/nokogiri_adapter"
25
+ require_relative "../lib/lutaml/model/xml_adapter/ox_adapter"
26
+ require_relative "../lib/lutaml/model/toml_adapter/toml_rb_adapter"
27
+
28
+ Lutaml::Model::Config.configure do |config|
29
+ config.xml_adapter_type = :nokogiri
30
+ config.json_adapter_type = :standard_json
31
+ config.yaml_adapter_type = :standard_yaml
32
+ config.toml_adapter_type = :toml_rb
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.23
4
+ version: 0.3.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-05 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -59,8 +59,10 @@ files:
59
59
  - lib/lutaml/model/error/collection_count_out_of_range_error.rb
60
60
  - lib/lutaml/model/error/incorrect_mapping_argument_error.rb
61
61
  - lib/lutaml/model/error/invalid_value_error.rb
62
+ - lib/lutaml/model/error/type_error.rb
62
63
  - lib/lutaml/model/error/type_not_enabled_error.rb
63
64
  - lib/lutaml/model/error/unknown_adapter_type_error.rb
65
+ - lib/lutaml/model/error/unknown_type_error.rb
64
66
  - lib/lutaml/model/error/validation_error.rb
65
67
  - lib/lutaml/model/json_adapter.rb
66
68
  - lib/lutaml/model/json_adapter/json_document.rb
@@ -86,8 +88,17 @@ files:
86
88
  - lib/lutaml/model/toml_adapter/toml_rb_adapter.rb
87
89
  - lib/lutaml/model/toml_adapter/tomlib_adapter.rb
88
90
  - lib/lutaml/model/type.rb
91
+ - lib/lutaml/model/type/boolean.rb
92
+ - lib/lutaml/model/type/date.rb
89
93
  - lib/lutaml/model/type/date_time.rb
94
+ - lib/lutaml/model/type/decimal.rb
95
+ - lib/lutaml/model/type/float.rb
96
+ - lib/lutaml/model/type/hash.rb
97
+ - lib/lutaml/model/type/integer.rb
98
+ - lib/lutaml/model/type/string.rb
99
+ - lib/lutaml/model/type/time.rb
90
100
  - lib/lutaml/model/type/time_without_date.rb
101
+ - lib/lutaml/model/type/value.rb
91
102
  - lib/lutaml/model/utils.rb
92
103
  - lib/lutaml/model/validation.rb
93
104
  - lib/lutaml/model/version.rb
@@ -109,6 +120,59 @@ files:
109
120
  - lib/lutaml/model/yaml_adapter/yaml_object.rb
110
121
  - lutaml-model.gemspec
111
122
  - sig/lutaml/model.rbs
123
+ - spec/address_spec.rb
124
+ - spec/fixtures/address.rb
125
+ - spec/fixtures/person.rb
126
+ - spec/fixtures/sample_model.rb
127
+ - spec/fixtures/vase.rb
128
+ - spec/fixtures/xml/special_char.xml
129
+ - spec/lutaml/model/attribute_spec.rb
130
+ - spec/lutaml/model/collection_spec.rb
131
+ - spec/lutaml/model/comparable_model_spec.rb
132
+ - spec/lutaml/model/custom_model_spec.rb
133
+ - spec/lutaml/model/custom_serialization_spec.rb
134
+ - spec/lutaml/model/defaults_spec.rb
135
+ - spec/lutaml/model/delegation_spec.rb
136
+ - spec/lutaml/model/inheritance_spec.rb
137
+ - spec/lutaml/model/json_adapter_spec.rb
138
+ - spec/lutaml/model/key_value_mapping_spec.rb
139
+ - spec/lutaml/model/map_content_spec.rb
140
+ - spec/lutaml/model/mixed_content_spec.rb
141
+ - spec/lutaml/model/namespace_spec.rb
142
+ - spec/lutaml/model/ordered_content_spec.rb
143
+ - spec/lutaml/model/render_nil_spec.rb
144
+ - spec/lutaml/model/schema/json_schema_spec.rb
145
+ - spec/lutaml/model/schema/relaxng_schema_spec.rb
146
+ - spec/lutaml/model/schema/xsd_schema_spec.rb
147
+ - spec/lutaml/model/schema/yaml_schema_spec.rb
148
+ - spec/lutaml/model/serializable_spec.rb
149
+ - spec/lutaml/model/serializable_validation_spec.rb
150
+ - spec/lutaml/model/simple_model_spec.rb
151
+ - spec/lutaml/model/toml_adapter_spec.rb
152
+ - spec/lutaml/model/type/boolean_spec.rb
153
+ - spec/lutaml/model/type/date_spec.rb
154
+ - spec/lutaml/model/type/date_time_spec.rb
155
+ - spec/lutaml/model/type/decimal_spec.rb
156
+ - spec/lutaml/model/type/float_spec.rb
157
+ - spec/lutaml/model/type/hash_spec.rb
158
+ - spec/lutaml/model/type/integer_spec.rb
159
+ - spec/lutaml/model/type/string_spec.rb
160
+ - spec/lutaml/model/type/time_spec.rb
161
+ - spec/lutaml/model/type/time_without_date_spec.rb
162
+ - spec/lutaml/model/type_spec.rb
163
+ - spec/lutaml/model/utils_spec.rb
164
+ - spec/lutaml/model/validation_spec.rb
165
+ - spec/lutaml/model/with_child_mapping_spec.rb
166
+ - spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb
167
+ - spec/lutaml/model/xml_adapter/oga_adapter_spec.rb
168
+ - spec/lutaml/model/xml_adapter/ox_adapter_spec.rb
169
+ - spec/lutaml/model/xml_adapter/xml_namespace_spec.rb
170
+ - spec/lutaml/model/xml_adapter_spec.rb
171
+ - spec/lutaml/model/xml_mapping_spec.rb
172
+ - spec/lutaml/model/yaml_adapter_spec.rb
173
+ - spec/lutaml/model_spec.rb
174
+ - spec/person_spec.rb
175
+ - spec/spec_helper.rb
112
176
  homepage: https://github.com/lutaml/lutaml-model
113
177
  licenses:
114
178
  - BSD-2-Clause