lutaml-model 0.4.0 → 0.5.1
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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +36 -20
- data/README.adoc +1003 -192
- data/lib/lutaml/model/attribute.rb +6 -2
- data/lib/lutaml/model/error/collection_true_missing_error.rb +16 -0
- data/lib/lutaml/model/error/multiple_mappings_error.rb +6 -0
- data/lib/lutaml/model/error.rb +2 -0
- data/lib/lutaml/model/key_value_mapping.rb +25 -4
- data/lib/lutaml/model/key_value_mapping_rule.rb +16 -3
- data/lib/lutaml/model/loggable.rb +15 -0
- data/lib/lutaml/model/mapping_rule.rb +14 -2
- data/lib/lutaml/model/serialize.rb +114 -64
- data/lib/lutaml/model/type/decimal.rb +5 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/builder/nokogiri.rb +1 -0
- data/lib/lutaml/model/xml_adapter/builder/oga.rb +180 -0
- data/lib/lutaml/model/xml_adapter/builder/ox.rb +1 -0
- data/lib/lutaml/model/xml_adapter/oga/document.rb +20 -0
- data/lib/lutaml/model/xml_adapter/oga/element.rb +117 -0
- data/lib/lutaml/model/xml_adapter/oga_adapter.rb +77 -44
- data/lib/lutaml/model/xml_adapter/xml_document.rb +14 -12
- data/lib/lutaml/model/xml_mapping.rb +3 -0
- data/lib/lutaml/model/xml_mapping_rule.rb +13 -4
- data/lib/lutaml/model.rb +1 -0
- data/spec/address_spec.rb +1 -0
- data/spec/fixtures/sample_model.rb +7 -0
- data/spec/lutaml/model/custom_model_spec.rb +47 -1
- data/spec/lutaml/model/included_spec.rb +192 -0
- data/spec/lutaml/model/mixed_content_spec.rb +48 -32
- data/spec/lutaml/model/multiple_mapping_spec.rb +329 -0
- data/spec/lutaml/model/ordered_content_spec.rb +1 -1
- data/spec/lutaml/model/render_nil_spec.rb +3 -0
- data/spec/lutaml/model/root_mappings_spec.rb +297 -0
- data/spec/lutaml/model/serializable_spec.rb +42 -7
- data/spec/lutaml/model/type/boolean_spec.rb +62 -0
- data/spec/lutaml/model/with_child_mapping_spec.rb +182 -0
- data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +11 -11
- data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +67 -1
- data/spec/lutaml/model/xml_adapter_spec.rb +2 -2
- data/spec/lutaml/model/xml_mapping_spec.rb +32 -9
- data/spec/sample_model_spec.rb +114 -0
- metadata +12 -2
@@ -0,0 +1,114 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require_relative "fixtures/sample_model"
|
3
|
+
|
4
|
+
RSpec.describe SampleModel do
|
5
|
+
let(:model) { described_class.new(attributes) }
|
6
|
+
let(:attributes_yaml) do
|
7
|
+
{
|
8
|
+
"name" => "John Doe",
|
9
|
+
"age" => 25,
|
10
|
+
"balance" => "100432423.523142344124",
|
11
|
+
"tags" => [
|
12
|
+
{ "text" => "ruby" },
|
13
|
+
{ "text" => "coding" },
|
14
|
+
],
|
15
|
+
"preferences" => { notifications: false, theme: "dark" },
|
16
|
+
"status" => "premium",
|
17
|
+
"large_number" => 9999,
|
18
|
+
"email" => "john@example.com",
|
19
|
+
"role" => "admin",
|
20
|
+
}
|
21
|
+
end
|
22
|
+
let(:attributes) do
|
23
|
+
{
|
24
|
+
name: "John Doe",
|
25
|
+
age: 25,
|
26
|
+
balance: BigDecimal("100432423.523142344124"),
|
27
|
+
tags: [
|
28
|
+
SampleModelTag.new(text: "ruby"),
|
29
|
+
SampleModelTag.new(text: "coding"),
|
30
|
+
],
|
31
|
+
preferences: { notifications: false, theme: "dark" },
|
32
|
+
status: "premium",
|
33
|
+
large_number: 9999,
|
34
|
+
email: "john@example.com",
|
35
|
+
role: "admin",
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "default values" do
|
40
|
+
let(:model) { described_class.new }
|
41
|
+
|
42
|
+
it "sets default name" do
|
43
|
+
expect(model.name).to eq("Anonymous")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sets default age" do
|
47
|
+
expect(model.age).to eq(18)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "sets default balance" do
|
51
|
+
expect(model.balance).to eq(BigDecimal("0.0"))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sets default tags" do
|
55
|
+
expect(model.tags).to eq([])
|
56
|
+
end
|
57
|
+
|
58
|
+
it "sets default preferences" do
|
59
|
+
expect(model.preferences).to eq({ notifications: true })
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sets default status" do
|
63
|
+
expect(model.status).to eq("active")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets default large_number" do
|
67
|
+
expect(model.large_number).to eq(0)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "sets default email" do
|
71
|
+
expect(model.email).to eq("example@example.com")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "sets default role" do
|
75
|
+
expect(model.role).to eq("user")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "role validation" do
|
80
|
+
it "accepts valid roles" do
|
81
|
+
%w[user admin guest].each do |role|
|
82
|
+
model.role = role
|
83
|
+
expect(model.role).to eq(role)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "raises error for invalid role" do
|
88
|
+
model.role = "invalid"
|
89
|
+
expect { model.validate! }.to raise_error(Lutaml::Model::ValidationError)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "YAML serialization" do
|
94
|
+
it "serializes to YAML" do
|
95
|
+
expect(model.to_yaml).to eq(attributes_yaml.to_yaml)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "deserializes from YAML" do
|
99
|
+
yaml = attributes_yaml.to_yaml
|
100
|
+
sample = described_class.from_yaml(yaml)
|
101
|
+
|
102
|
+
expect(sample.name).to eq("John Doe")
|
103
|
+
expect(sample.age).to eq(25)
|
104
|
+
expect(sample.balance).to eq(BigDecimal("100432423.523142344124"))
|
105
|
+
expect(sample.tags).to all(be_a(SampleModelTag))
|
106
|
+
expect(sample.tags.map(&:text)).to eq(["ruby", "coding"])
|
107
|
+
expect(sample.preferences).to eq({ notifications: false, theme: "dark" })
|
108
|
+
expect(sample.status).to eq("premium")
|
109
|
+
expect(sample.large_number).to eq(9999)
|
110
|
+
expect(sample.email).to eq("john@example.com")
|
111
|
+
expect(sample.role).to eq("admin")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
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.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-09 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/config.rb
|
60
60
|
- lib/lutaml/model/error.rb
|
61
61
|
- lib/lutaml/model/error/collection_count_out_of_range_error.rb
|
62
|
+
- lib/lutaml/model/error/collection_true_missing_error.rb
|
62
63
|
- lib/lutaml/model/error/incorrect_mapping_argument_error.rb
|
63
64
|
- lib/lutaml/model/error/invalid_value_error.rb
|
65
|
+
- lib/lutaml/model/error/multiple_mappings_error.rb
|
64
66
|
- lib/lutaml/model/error/pattern_not_matched_error.rb
|
65
67
|
- lib/lutaml/model/error/type_error.rb
|
66
68
|
- lib/lutaml/model/error/type_not_enabled_error.rb
|
@@ -74,6 +76,7 @@ files:
|
|
74
76
|
- lib/lutaml/model/json_adapter/standard_json_adapter.rb
|
75
77
|
- lib/lutaml/model/key_value_mapping.rb
|
76
78
|
- lib/lutaml/model/key_value_mapping_rule.rb
|
79
|
+
- lib/lutaml/model/loggable.rb
|
77
80
|
- lib/lutaml/model/mapping_hash.rb
|
78
81
|
- lib/lutaml/model/mapping_rule.rb
|
79
82
|
- lib/lutaml/model/schema.rb
|
@@ -107,8 +110,11 @@ files:
|
|
107
110
|
- lib/lutaml/model/version.rb
|
108
111
|
- lib/lutaml/model/xml_adapter.rb
|
109
112
|
- lib/lutaml/model/xml_adapter/builder/nokogiri.rb
|
113
|
+
- lib/lutaml/model/xml_adapter/builder/oga.rb
|
110
114
|
- lib/lutaml/model/xml_adapter/builder/ox.rb
|
111
115
|
- lib/lutaml/model/xml_adapter/nokogiri_adapter.rb
|
116
|
+
- lib/lutaml/model/xml_adapter/oga/document.rb
|
117
|
+
- lib/lutaml/model/xml_adapter/oga/element.rb
|
112
118
|
- lib/lutaml/model/xml_adapter/oga_adapter.rb
|
113
119
|
- lib/lutaml/model/xml_adapter/ox_adapter.rb
|
114
120
|
- lib/lutaml/model/xml_adapter/xml_attribute.rb
|
@@ -140,14 +146,17 @@ files:
|
|
140
146
|
- spec/lutaml/model/defaults_spec.rb
|
141
147
|
- spec/lutaml/model/delegation_spec.rb
|
142
148
|
- spec/lutaml/model/enum_spec.rb
|
149
|
+
- spec/lutaml/model/included_spec.rb
|
143
150
|
- spec/lutaml/model/inheritance_spec.rb
|
144
151
|
- spec/lutaml/model/json_adapter_spec.rb
|
145
152
|
- spec/lutaml/model/key_value_mapping_spec.rb
|
146
153
|
- spec/lutaml/model/map_content_spec.rb
|
147
154
|
- spec/lutaml/model/mixed_content_spec.rb
|
155
|
+
- spec/lutaml/model/multiple_mapping_spec.rb
|
148
156
|
- spec/lutaml/model/namespace_spec.rb
|
149
157
|
- spec/lutaml/model/ordered_content_spec.rb
|
150
158
|
- spec/lutaml/model/render_nil_spec.rb
|
159
|
+
- spec/lutaml/model/root_mappings_spec.rb
|
151
160
|
- spec/lutaml/model/schema/json_schema_spec.rb
|
152
161
|
- spec/lutaml/model/schema/relaxng_schema_spec.rb
|
153
162
|
- spec/lutaml/model/schema/xsd_schema_spec.rb
|
@@ -179,6 +188,7 @@ files:
|
|
179
188
|
- spec/lutaml/model/yaml_adapter_spec.rb
|
180
189
|
- spec/lutaml/model_spec.rb
|
181
190
|
- spec/person_spec.rb
|
191
|
+
- spec/sample_model_spec.rb
|
182
192
|
- spec/spec_helper.rb
|
183
193
|
homepage: https://github.com/lutaml/lutaml-model
|
184
194
|
licenses:
|