lutaml-model 0.3.10 → 0.3.12
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.
Potentially problematic release.
This version of lutaml-model might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +23 -23
- data/Gemfile +1 -0
- data/LICENSE.md +33 -0
- data/README.adoc +167 -13
- data/lib/lutaml/model/attribute.rb +28 -3
- data/lib/lutaml/model/error/incorrect_mapping_argument_error.rb +6 -0
- data/lib/lutaml/model/error/type_not_enabled_error.rb +9 -0
- data/lib/lutaml/model/error.rb +2 -0
- data/lib/lutaml/model/json_adapter/standard_json_adapter.rb +1 -2
- data/lib/lutaml/model/key_value_mapping.rb +15 -1
- data/lib/lutaml/model/mapping_hash.rb +14 -0
- data/lib/lutaml/model/mapping_rule.rb +50 -7
- data/lib/lutaml/model/serialize.rb +118 -62
- data/lib/lutaml/model/type.rb +10 -0
- data/lib/lutaml/model/utils.rb +16 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/builder/nokogiri.rb +14 -6
- data/lib/lutaml/model/xml_adapter/builder/ox.rb +4 -0
- data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +20 -9
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +9 -1
- data/lib/lutaml/model/xml_adapter/xml_document.rb +82 -35
- data/lib/lutaml/model/xml_adapter/xml_element.rb +13 -3
- data/lib/lutaml/model/xml_adapter/xml_namespace.rb +1 -1
- data/lib/lutaml/model/xml_mapping.rb +38 -9
- data/lib/lutaml/model/xml_mapping_rule.rb +5 -1
- data/lib/lutaml/model/yaml_adapter/standard_yaml_adapter.rb +10 -5
- data/lutaml-model.gemspec +0 -1
- metadata +5 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 345649756b1331313e2ce36666a74d5d74476d4a78cc45d5e672e02d567153e6
|
4
|
+
data.tar.gz: adf1aff67862a8c6c6f8aac304dd819042c437460f3baf31625563e94c2aa73f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35865f10010a06f9ebd4be5feb988d376d5bd9a960c2e10eb9c786dd346ab97f61fc41f8d0cb09ab5f280f75e4cbb7ab1b52ca36ee8fa45b64629e349b7ea1ea
|
7
|
+
data.tar.gz: 68d128827defc77d8e06e3b227f435ff4d3046c0f47c7570fc966adf58c830907b146f78e9baaafe3b11b719c86bb6778f10ae9e08e03af95f2e172ba392ca9c
|
data/.rubocop_todo.yml
CHANGED
@@ -1,25 +1,18 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2024-
|
3
|
+
# on 2024-10-08 13:33:09 UTC using RuboCop version 1.66.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 108
|
10
10
|
# This cop supports safe autocorrection (--autocorrect).
|
11
11
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
12
12
|
# URISchemes: http, https
|
13
13
|
Layout/LineLength:
|
14
14
|
Enabled: false
|
15
15
|
|
16
|
-
# Offense count: 1
|
17
|
-
# This cop supports safe autocorrection (--autocorrect).
|
18
|
-
# Configuration parameters: AllowInHeredoc.
|
19
|
-
Layout/TrailingWhitespace:
|
20
|
-
Exclude:
|
21
|
-
- 'lib/lutaml/model/schema_location.rb'
|
22
|
-
|
23
16
|
# Offense count: 11
|
24
17
|
# Configuration parameters: AllowedMethods.
|
25
18
|
# AllowedMethods: enums
|
@@ -37,12 +30,13 @@ Lint/DuplicateMethods:
|
|
37
30
|
Exclude:
|
38
31
|
- 'lib/lutaml/model/attribute.rb'
|
39
32
|
|
40
|
-
# Offense count:
|
33
|
+
# Offense count: 35
|
41
34
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
42
35
|
Metrics/AbcSize:
|
43
36
|
Exclude:
|
44
37
|
- 'lib/lutaml/model/attribute.rb'
|
45
38
|
- 'lib/lutaml/model/comparable_model.rb'
|
39
|
+
- 'lib/lutaml/model/mapping_rule.rb'
|
46
40
|
- 'lib/lutaml/model/schema/relaxng_schema.rb'
|
47
41
|
- 'lib/lutaml/model/schema/xsd_schema.rb'
|
48
42
|
- 'lib/lutaml/model/serialize.rb'
|
@@ -51,13 +45,13 @@ Metrics/AbcSize:
|
|
51
45
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
52
46
|
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
53
47
|
|
54
|
-
# Offense count:
|
48
|
+
# Offense count: 4
|
55
49
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
56
50
|
# AllowedMethods: refine
|
57
51
|
Metrics/BlockLength:
|
58
|
-
Max:
|
52
|
+
Max: 47
|
59
53
|
|
60
|
-
# Offense count:
|
54
|
+
# Offense count: 27
|
61
55
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
62
56
|
Metrics/CyclomaticComplexity:
|
63
57
|
Exclude:
|
@@ -69,17 +63,17 @@ Metrics/CyclomaticComplexity:
|
|
69
63
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
70
64
|
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
71
65
|
|
72
|
-
# Offense count:
|
66
|
+
# Offense count: 46
|
73
67
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
74
68
|
Metrics/MethodLength:
|
75
|
-
Max:
|
69
|
+
Max: 51
|
76
70
|
|
77
71
|
# Offense count: 4
|
78
72
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
79
73
|
Metrics/ParameterLists:
|
80
|
-
Max:
|
74
|
+
Max: 11
|
81
75
|
|
82
|
-
# Offense count:
|
76
|
+
# Offense count: 22
|
83
77
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
84
78
|
Metrics/PerceivedComplexity:
|
85
79
|
Exclude:
|
@@ -100,10 +94,10 @@ RSpec/ContextWording:
|
|
100
94
|
- 'spec/lutaml/model/xml_adapter/ox_adapter_spec.rb'
|
101
95
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
102
96
|
|
103
|
-
# Offense count:
|
97
|
+
# Offense count: 105
|
104
98
|
# Configuration parameters: CountAsOne.
|
105
99
|
RSpec/ExampleLength:
|
106
|
-
Max:
|
100
|
+
Max: 54
|
107
101
|
|
108
102
|
# Offense count: 2
|
109
103
|
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
|
@@ -129,11 +123,11 @@ RSpec/MultipleDescribes:
|
|
129
123
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
130
124
|
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
131
125
|
|
132
|
-
# Offense count:
|
126
|
+
# Offense count: 99
|
133
127
|
RSpec/MultipleExpectations:
|
134
|
-
Max:
|
128
|
+
Max: 14
|
135
129
|
|
136
|
-
# Offense count:
|
130
|
+
# Offense count: 18
|
137
131
|
# Configuration parameters: AllowSubject.
|
138
132
|
RSpec/MultipleMemoizedHelpers:
|
139
133
|
Max: 9
|
@@ -147,18 +141,24 @@ RSpec/PendingWithoutReason:
|
|
147
141
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
148
142
|
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
149
143
|
|
144
|
+
# Offense count: 1
|
145
|
+
RSpec/RemoveConst:
|
146
|
+
Exclude:
|
147
|
+
- 'spec/lutaml/model/type/decimal_spec.rb'
|
148
|
+
|
150
149
|
# Offense count: 2
|
151
150
|
RSpec/RepeatedExampleGroupDescription:
|
152
151
|
Exclude:
|
153
152
|
- 'spec/lutaml/model/collection_spec.rb'
|
154
153
|
|
155
|
-
# Offense count:
|
154
|
+
# Offense count: 2
|
156
155
|
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
|
157
156
|
# Include: **/*_spec.rb
|
158
157
|
RSpec/SpecFilePathFormat:
|
159
158
|
Exclude:
|
160
159
|
- '**/spec/routing/**/*'
|
161
160
|
- 'spec/lutaml/model/collection_spec.rb'
|
161
|
+
- 'spec/lutaml/model/type/decimal_spec.rb'
|
162
162
|
|
163
163
|
# Offense count: 1
|
164
164
|
Security/CompoundHash:
|
data/Gemfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
Licenses & Copyright
|
2
|
+
====================
|
3
|
+
|
4
|
+
This license file adheres to the formatting guidelines of
|
5
|
+
[readable-licenses](https://github.com/nevir/readable-licenses).
|
6
|
+
|
7
|
+
|
8
|
+
Ribose's BSD 2-Clause License
|
9
|
+
-----------------------------
|
10
|
+
|
11
|
+
Copyright (c) 2024, [Ribose Inc](https://www.ribose.com).
|
12
|
+
All rights reserved.
|
13
|
+
|
14
|
+
Redistribution and use in source and binary forms, with or without modification,
|
15
|
+
are permitted provided that the following conditions are met:
|
16
|
+
|
17
|
+
1. Redistributions of source code must retain the above copyright notice,
|
18
|
+
this list of conditions and the following disclaimer.
|
19
|
+
|
20
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
21
|
+
this list of conditions and the following disclaimer in the documentation
|
22
|
+
and/or other materials provided with the distribution.
|
23
|
+
|
24
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
25
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
26
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
28
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
29
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
30
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
31
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
32
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
33
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
CHANGED
@@ -145,6 +145,8 @@ same class and all their attributes are equal.
|
|
145
145
|
|
146
146
|
=== Supported attribute value types
|
147
147
|
|
148
|
+
==== General types
|
149
|
+
|
148
150
|
Lutaml::Model supports the following attribute types, they can be
|
149
151
|
referred by a string, a symbol, or their class constant.
|
150
152
|
|
@@ -166,12 +168,11 @@ attribute :name_of_attribute, {symbol | string | class}
|
|
166
168
|
| `DateTime` | `:date_time` | `Lutaml::Model::Type::DateTime` | `::DateTime`
|
167
169
|
| `TimeWithoutDate` | `:time_without_date` | `Lutaml::Model::Type::TimeWithoutDate` | `::Time`
|
168
170
|
| `Boolean` | `:boolean` | `Lutaml::Model::Type::Boolean` | `Boolean`
|
169
|
-
| `Decimal` | `:decimal` | `Lutaml::Model::Type::Decimal` | `::BigDecimal`
|
171
|
+
| `Decimal` (optional) | `:decimal` | `Lutaml::Model::Type::Decimal` | `::BigDecimal`
|
170
172
|
| `Hash` | `:hash` | `Lutaml::Model::Type::Hash` | `::Hash`
|
171
173
|
|
172
174
|
|===
|
173
175
|
|
174
|
-
|
175
176
|
.Defining attributes with supported types via symbol, string and class
|
176
177
|
[example]
|
177
178
|
====
|
@@ -198,6 +199,23 @@ end
|
|
198
199
|
----
|
199
200
|
====
|
200
201
|
|
202
|
+
==== (optional) Decimal type
|
203
|
+
|
204
|
+
The `BigDecimal` class is no longer part of the standard Ruby library from Ruby
|
205
|
+
3.4 onwards, hence the `Decimal` type is only enabled when the `bigdecimal`
|
206
|
+
library is loaded.
|
207
|
+
|
208
|
+
This means that the following code needs to be run before using (and parsing)
|
209
|
+
the `Decimal` type:
|
210
|
+
|
211
|
+
[source,ruby]
|
212
|
+
----
|
213
|
+
require 'bigdecimal'
|
214
|
+
----
|
215
|
+
|
216
|
+
If the `bigdecimal` library is not loaded, usage of the `Decimal` type will
|
217
|
+
raise a `Lutaml::Model::TypeNotSupportedError`.
|
218
|
+
|
201
219
|
|
202
220
|
=== Attribute as a collection
|
203
221
|
|
@@ -405,6 +423,51 @@ end
|
|
405
423
|
----
|
406
424
|
====
|
407
425
|
|
426
|
+
=== Attribute as raw string
|
427
|
+
|
428
|
+
An attribute can be set to read the value as raw string for XML, by using the `raw: true` option.
|
429
|
+
|
430
|
+
Syntax:
|
431
|
+
|
432
|
+
[source,ruby]
|
433
|
+
----
|
434
|
+
attribute :name_of_attribute, :string, raw: true
|
435
|
+
----
|
436
|
+
|
437
|
+
.Using the `raw` option to read raw value for an XML attribute
|
438
|
+
[example]
|
439
|
+
====
|
440
|
+
[source,ruby]
|
441
|
+
----
|
442
|
+
class Person < Lutaml::Model::Serializable
|
443
|
+
attribute :name, :string
|
444
|
+
attribute :description, :string, raw: true
|
445
|
+
end
|
446
|
+
----
|
447
|
+
|
448
|
+
For the following xml
|
449
|
+
[source,xml]
|
450
|
+
----
|
451
|
+
<Person>
|
452
|
+
<name>John Doe</name>
|
453
|
+
<description>
|
454
|
+
A <b>fictional person</b> commonly used as a <i>placeholder name</i>.
|
455
|
+
</description>
|
456
|
+
</Person>
|
457
|
+
----
|
458
|
+
|
459
|
+
[source,ruby]
|
460
|
+
----
|
461
|
+
> Person.from_xml(xml)
|
462
|
+
> # <Person:0x0000000107a3ca70
|
463
|
+
@description="\n A <b>fictional person</b> commonly used as a <i>placeholder name</i>.\n ",
|
464
|
+
@element_order=["text", "name", "text", "description", "text"],
|
465
|
+
@name="John Doe",
|
466
|
+
@ordered=nil,
|
467
|
+
@validate_on_set=false>
|
468
|
+
----
|
469
|
+
====
|
470
|
+
|
408
471
|
== Serialization model mappings
|
409
472
|
|
410
473
|
=== General
|
@@ -989,7 +1052,7 @@ end
|
|
989
1052
|
|
990
1053
|
TODO: How to create mixed content from `#new`?
|
991
1054
|
|
992
|
-
|
1055
|
+
[[xml-schema-location]]
|
993
1056
|
==== Automatic support of `xsi:schemaLocation`
|
994
1057
|
|
995
1058
|
The
|
@@ -1444,9 +1507,14 @@ NOTE: The corresponding keyword used by Shale is `receiver:` instead of
|
|
1444
1507
|
|
1445
1508
|
==== Attribute serialization with custom methods
|
1446
1509
|
|
1510
|
+
===== General
|
1511
|
+
|
1447
1512
|
Define custom methods for specific attribute mappings using the `with:` key for
|
1448
1513
|
each serialization mapping block for `from` and `to`.
|
1449
1514
|
|
1515
|
+
|
1516
|
+
===== XML serialization with custom methods
|
1517
|
+
|
1450
1518
|
Syntax:
|
1451
1519
|
|
1452
1520
|
.XML serialization with custom methods
|
@@ -1468,6 +1536,81 @@ xml do
|
|
1468
1536
|
end
|
1469
1537
|
----
|
1470
1538
|
|
1539
|
+
.Using the `with:` key to define custom serialization methods for XML
|
1540
|
+
[example]
|
1541
|
+
====
|
1542
|
+
The following class will parse the XML snippet below:
|
1543
|
+
|
1544
|
+
[source,ruby]
|
1545
|
+
----
|
1546
|
+
class CustomCeramic < Lutaml::Model::Serializable
|
1547
|
+
attribute :name, :string
|
1548
|
+
attribute :size, :integer
|
1549
|
+
attribute :description, :string
|
1550
|
+
|
1551
|
+
xml do
|
1552
|
+
map_element "Name", to: :name, with: { to: :name_to_xml, from: :name_from_xml }
|
1553
|
+
map_attribute "Size", to: :size, with: { to: :size_to_xml, from: :size_from_xml }
|
1554
|
+
map_content with: { to: :description_to_xml, from: :description_from_xml }
|
1555
|
+
end
|
1556
|
+
|
1557
|
+
def name_to_xml(model, parent, doc)
|
1558
|
+
el = doc.create_element("Name")
|
1559
|
+
doc.add_text(el, "XML Masterpiece: #{model.name}")
|
1560
|
+
doc.add_element(parent, el)
|
1561
|
+
end
|
1562
|
+
|
1563
|
+
def name_from_xml(model, value)
|
1564
|
+
model.name = value.sub(/^XML Masterpiece: /, "")
|
1565
|
+
end
|
1566
|
+
|
1567
|
+
def size_to_xml(model, parent, doc)
|
1568
|
+
doc.add_attribute(parent, "Size", model.size + 3)
|
1569
|
+
end
|
1570
|
+
|
1571
|
+
def size_from_xml(model, value)
|
1572
|
+
model.size = value.to_i - 3
|
1573
|
+
end
|
1574
|
+
|
1575
|
+
def description_to_xml(model, parent, doc)
|
1576
|
+
doc.add_text(parent, "XML Description: #{model.description}")
|
1577
|
+
end
|
1578
|
+
|
1579
|
+
def description_from_xml(model, value)
|
1580
|
+
model.description = value.join.strip.sub(/^XML Description: /, "")
|
1581
|
+
end
|
1582
|
+
end
|
1583
|
+
----
|
1584
|
+
|
1585
|
+
[source,xml]
|
1586
|
+
----
|
1587
|
+
<CustomCeramic Size="15">
|
1588
|
+
<Name>XML Masterpiece: Vase</Name>
|
1589
|
+
XML Description: A beautiful ceramic vase
|
1590
|
+
</CustomCeramic>
|
1591
|
+
----
|
1592
|
+
|
1593
|
+
[source,ruby]
|
1594
|
+
----
|
1595
|
+
> CustomCeramic.from_xml(xml)
|
1596
|
+
> #<CustomCeramic:0x0000000108d0e1f8
|
1597
|
+
@element_order=["text", "Name", "text", "Size", "text"],
|
1598
|
+
@name="Masterpiece: Vase",
|
1599
|
+
@ordered=nil,
|
1600
|
+
@size=12,
|
1601
|
+
@description="A beautiful ceramic vase",
|
1602
|
+
@validate_on_set=false>
|
1603
|
+
> puts CustomCeramic.new(name: "Vase", size: 12, description: "A beautiful vase").to_xml
|
1604
|
+
# <CustomCeramic Size="15">
|
1605
|
+
# <Name>XML Masterpiece: Vase</Name>
|
1606
|
+
# XML Description: A beautiful vase
|
1607
|
+
# </CustomCeramic>
|
1608
|
+
----
|
1609
|
+
====
|
1610
|
+
|
1611
|
+
|
1612
|
+
===== Key-value data model serialization with custom methods
|
1613
|
+
|
1471
1614
|
.Key-value data model serialization with custom methods
|
1472
1615
|
[source,ruby]
|
1473
1616
|
----
|
@@ -1524,7 +1667,7 @@ end
|
|
1524
1667
|
|
1525
1668
|
|
1526
1669
|
[[attribute-extraction]]
|
1527
|
-
==== Attribute extraction
|
1670
|
+
==== Attribute extraction (for key-value data models only)
|
1528
1671
|
|
1529
1672
|
NOTE: This feature is for key-value data model serialization only.
|
1530
1673
|
|
@@ -1992,9 +2135,9 @@ differences in implementation.
|
|
1992
2135
|
|
|
1993
2136
|
|
1994
2137
|
| Value types
|
1995
|
-
| `Lutaml::Model::Type` includes: `Integer`, `String`, `Float`, `Boolean`, `Date`, `DateTime`, `Time`, `Hash`.
|
2138
|
+
| `Lutaml::Model::Type` includes: `Integer`, `String`, `Float`, `Boolean`, `Date`, `DateTime`, `Time`, `Decimal`, `Hash`.
|
1996
2139
|
| `Shale::Type` includes: `Integer`, `String`, `Float`, `Boolean`, `Date`, `Time`.
|
1997
|
-
| Lutaml::Model supports
|
2140
|
+
| Lutaml::Model supports additional value types `Decimal`, `DateTime` and `Hash`.
|
1998
2141
|
|
1999
2142
|
| Configuration
|
2000
2143
|
| `Lutaml::Model::Config`
|
@@ -2011,6 +2154,11 @@ differences in implementation.
|
|
2011
2154
|
| XML, YAML, JSON, TOML, CSV
|
2012
2155
|
| Lutaml::Model does not support CSV.
|
2013
2156
|
|
2157
|
+
| Validation
|
2158
|
+
| Supports collection range, fixed values, and custom validation
|
2159
|
+
| Requires implementation
|
2160
|
+
|
|
2161
|
+
|
2014
2162
|
| Adapter support
|
2015
2163
|
| XML (Nokogiri, Ox, Oga), YAML, JSON (JSON, MultiJson), TOML (Toml-rb, Tomlib)
|
2016
2164
|
| XML (Nokogiri, Ox), YAML, JSON (JSON, MultiJson), TOML (Toml-rb, Tomlib), CSV
|
@@ -2042,6 +2190,12 @@ namespace from the root element.
|
|
2042
2190
|
| No.
|
2043
2191
|
|
|
2044
2192
|
|
2193
|
+
| Support for `xsi:schemaLocation`
|
2194
|
+
| Yes. Automatically supports the <<xml-schema-location,`xsi:schemaLocation`>>
|
2195
|
+
attribute for every element.
|
2196
|
+
| Requires manual specification on every XML element that uses it.
|
2197
|
+
|
|
2198
|
+
|
2045
2199
|
4+h| Attribute features
|
2046
2200
|
|
2047
2201
|
| Attribute delegation
|
@@ -2061,7 +2215,6 @@ data models.
|
|
2061
2215
|
| No.
|
2062
2216
|
| Lutaml::Model supports attribute extraction from key-value data models.
|
2063
2217
|
|
2064
|
-
|
2065
2218
|
|===
|
2066
2219
|
|
2067
2220
|
|
@@ -2114,25 +2267,26 @@ Actions:
|
|
2114
2267
|
|
2115
2268
|
=== Step 2: Replace value type definitions
|
2116
2269
|
|
2117
|
-
Value types in `Lutaml::Model` are under the `Lutaml::Model::Type` module
|
2270
|
+
Value types in `Lutaml::Model` are under the `Lutaml::Model::Type` module,
|
2271
|
+
or use the LutaML type symbols.
|
2118
2272
|
|
2119
2273
|
[source,ruby]
|
2120
2274
|
----
|
2121
2275
|
class Example < Lutaml::Model::Serializable
|
2122
|
-
attribute :length,
|
2123
|
-
attribute :description,
|
2276
|
+
attribute :length, :integer
|
2277
|
+
attribute :description, :string
|
2124
2278
|
end
|
2125
2279
|
----
|
2126
2280
|
|
2127
2281
|
[NOTE]
|
2128
2282
|
====
|
2129
|
-
`Lutaml::Model`
|
2283
|
+
`Lutaml::Model` supports specifying predefined value types as strings or
|
2130
2284
|
symbols, which is not supported by Shale.
|
2131
2285
|
|
2132
2286
|
[source,ruby]
|
2133
2287
|
----
|
2134
2288
|
class Example < Lutaml::Model::Serializable
|
2135
|
-
attribute :length,
|
2289
|
+
attribute :length, Lutaml::Model::Type::Integer
|
2136
2290
|
attribute :description, "String"
|
2137
2291
|
end
|
2138
2292
|
----
|
@@ -2369,6 +2523,6 @@ allowing you to shape and structure your data into useful forms.
|
|
2369
2523
|
== License and Copyright
|
2370
2524
|
|
2371
2525
|
This project is licensed under the BSD 2-clause License.
|
2372
|
-
See the LICENSE file for details.
|
2526
|
+
See the link:LICENSE.md[] file for details.
|
2373
2527
|
|
2374
2528
|
Copyright Ribose.
|
@@ -7,6 +7,7 @@ module Lutaml
|
|
7
7
|
@name = name
|
8
8
|
@type = cast_type(type)
|
9
9
|
@options = options
|
10
|
+
@raw = !!options[:raw]
|
10
11
|
|
11
12
|
if collection?
|
12
13
|
validate_collection_range
|
@@ -14,6 +15,10 @@ module Lutaml
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
def delegate
|
19
|
+
@options[:delegate]
|
20
|
+
end
|
21
|
+
|
17
22
|
def cast_type(type)
|
18
23
|
case type
|
19
24
|
when Class
|
@@ -27,6 +32,16 @@ module Lutaml
|
|
27
32
|
raise ArgumentError, "Unknown Lutaml::Model::Type: #{type}"
|
28
33
|
end
|
29
34
|
|
35
|
+
def cast_value(value)
|
36
|
+
return type.cast(value) unless value.is_a?(Array)
|
37
|
+
|
38
|
+
value.map { |v| type.cast(v) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def setter
|
42
|
+
:"#{@name}="
|
43
|
+
end
|
44
|
+
|
30
45
|
def collection?
|
31
46
|
options[:collection] || false
|
32
47
|
end
|
@@ -35,10 +50,20 @@ module Lutaml
|
|
35
50
|
!collection?
|
36
51
|
end
|
37
52
|
|
38
|
-
def
|
39
|
-
|
53
|
+
def raw?
|
54
|
+
@raw
|
55
|
+
end
|
40
56
|
|
41
|
-
|
57
|
+
def default
|
58
|
+
value = if delegate
|
59
|
+
type.attributes[to].default
|
60
|
+
elsif options[:default].is_a?(Proc)
|
61
|
+
options[:default].call
|
62
|
+
else
|
63
|
+
options[:default]
|
64
|
+
end
|
65
|
+
|
66
|
+
cast_value(value)
|
42
67
|
end
|
43
68
|
|
44
69
|
def render_nil?
|
data/lib/lutaml/model/error.rb
CHANGED
@@ -6,6 +6,8 @@ module Lutaml
|
|
6
6
|
end
|
7
7
|
|
8
8
|
require_relative "error/invalid_value_error"
|
9
|
+
require_relative "error/incorrect_mapping_argument_error"
|
9
10
|
require_relative "error/unknown_adapter_type_error"
|
10
11
|
require_relative "error/collection_count_out_of_range_error"
|
11
12
|
require_relative "error/validation_error"
|
13
|
+
require_relative "error/type_not_enabled_error"
|
@@ -11,12 +11,14 @@ module Lutaml
|
|
11
11
|
|
12
12
|
def map(
|
13
13
|
name,
|
14
|
-
to
|
14
|
+
to: nil,
|
15
15
|
render_nil: false,
|
16
16
|
with: {},
|
17
17
|
delegate: nil,
|
18
18
|
child_mappings: nil
|
19
19
|
)
|
20
|
+
validate!(name, to, with)
|
21
|
+
|
20
22
|
@mappings << KeyValueMappingRule.new(
|
21
23
|
name,
|
22
24
|
to: to,
|
@@ -28,6 +30,18 @@ module Lutaml
|
|
28
30
|
end
|
29
31
|
|
30
32
|
alias map_element map
|
33
|
+
|
34
|
+
def validate!(key, to, with)
|
35
|
+
if to.nil? && with.empty?
|
36
|
+
msg = ":to or :with argument is required for mapping '#{key}'"
|
37
|
+
raise IncorrectMappingArgumentsError.new(msg)
|
38
|
+
end
|
39
|
+
|
40
|
+
if !with.empty? && (with[:from].nil? || with[:to].nil?)
|
41
|
+
msg = ":with argument for mapping '#{key}' requires :to and :from keys"
|
42
|
+
raise IncorrectMappingArgumentsError.new(msg)
|
43
|
+
end
|
44
|
+
end
|
31
45
|
end
|
32
46
|
end
|
33
47
|
end
|
@@ -24,6 +24,20 @@ module Lutaml
|
|
24
24
|
@ordered
|
25
25
|
end
|
26
26
|
|
27
|
+
def method_missing(method_name, *args)
|
28
|
+
value = self[method_name] || self[method_name.to_s]
|
29
|
+
return value if value
|
30
|
+
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def respond_to_missing?(method_name, include_private = false)
|
35
|
+
key_present = key?(method_name) || key?(method_name.to_s)
|
36
|
+
return true if key_present
|
37
|
+
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
27
41
|
private
|
28
42
|
|
29
43
|
def normalize(key)
|