lutaml-model 0.8.193 → 0.8.194
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/lib/lutaml/json/type/serializers.rb +6 -4
- data/lib/lutaml/model/type/date.rb +17 -13
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/toml/type/serializers.rb +3 -2
- data/lib/lutaml/xml/type/serializers.rb +6 -4
- data/spec/lutaml/model/type/date_spec.rb +40 -12
- data/spec/lutaml/model/type/subclass_serialize_override_spec.rb +86 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d098251c4a1cee01a85101b7d12be79aea4d0bc550384134f635a44775544a09
|
|
4
|
+
data.tar.gz: 8a658f405ed484b917c058dd09ca80f4c3ea216dc93d9b30dd07b5b5fa7a58b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09978922557b9c1963aff3d1449dda08f9984ccba340b021242d1169b052948bb44ecf5a2db9205b878543da2fa1c1cce7e1496cc134576e10bd399782cb1e7a'
|
|
7
|
+
data.tar.gz: b245236ae74bcbf24859dd44ee64d649086ad9d83cef356e2361b9761c3b3bcb9b5af0b1fa6b058005fcb33f3e2ef69159035984c168f6eab71ab101e1f961ff
|
|
@@ -41,16 +41,18 @@ module Lutaml
|
|
|
41
41
|
}
|
|
42
42
|
)
|
|
43
43
|
|
|
44
|
-
# Date — ISO8601 with optional timezone
|
|
44
|
+
# Date — ISO8601 with optional timezone; delegates to the
|
|
45
|
+
# resolved type class (subclass serialize overrides fire)
|
|
45
46
|
v.register_format_type_serializer(
|
|
46
47
|
:json, Lutaml::Model::Type::Date,
|
|
47
|
-
to: ->(inst) {
|
|
48
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
48
49
|
)
|
|
49
50
|
|
|
50
|
-
# TimeWithoutDate — HH:MM:SS format
|
|
51
|
+
# TimeWithoutDate — HH:MM:SS format; delegates to the
|
|
52
|
+
# resolved type class
|
|
51
53
|
v.register_format_type_serializer(
|
|
52
54
|
:json, Lutaml::Model::Type::TimeWithoutDate,
|
|
53
|
-
to: ->(inst) {
|
|
55
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
54
56
|
)
|
|
55
57
|
|
|
56
58
|
# Symbol — :symbol: format
|
|
@@ -15,9 +15,10 @@ module Lutaml
|
|
|
15
15
|
|
|
16
16
|
case value
|
|
17
17
|
when ::DateTime
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
# Precision is the value: keep the time-of-day verbatim.
|
|
19
|
+
# Truncating here (or in serialize below) silently drops
|
|
20
|
+
# time components the consumer round-trips (issue #1256).
|
|
21
|
+
value
|
|
21
22
|
when ::Time
|
|
22
23
|
value.to_date
|
|
23
24
|
when ::Date
|
|
@@ -26,9 +27,15 @@ module Lutaml
|
|
|
26
27
|
str = value.to_s
|
|
27
28
|
tz_match = str.match(TIMEZONE_RE)
|
|
28
29
|
if tz_match
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
if str.sub(TIMEZONE_RE, "").include?(":")
|
|
31
|
+
# Time-of-day present: DateTime.parse keeps both the
|
|
32
|
+
# time and the zone (a bare date+zone loses the zone).
|
|
33
|
+
::DateTime.parse(str)
|
|
34
|
+
else
|
|
35
|
+
date = ::Date.parse(str.sub(TIMEZONE_RE, ""))
|
|
36
|
+
offset = parse_timezone(tz_match[1])
|
|
37
|
+
::DateTime.new(date.year, date.month, date.mday, 0, 0, 0, offset)
|
|
38
|
+
end
|
|
32
39
|
else
|
|
33
40
|
::Date.parse(str)
|
|
34
41
|
end
|
|
@@ -37,16 +44,13 @@ module Lutaml
|
|
|
37
44
|
nil
|
|
38
45
|
end
|
|
39
46
|
|
|
40
|
-
# xs:date
|
|
47
|
+
# xs:date for date-only values; the full ISO 8601 dateTime form
|
|
48
|
+
# when the value is a ::DateTime — cast and serialize agree, so
|
|
49
|
+
# a time carried into the type survives the round-trip.
|
|
41
50
|
def self.serialize(value)
|
|
42
51
|
return nil if value.nil?
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
when ::DateTime
|
|
46
|
-
value.strftime("%Y-%m-%d%:z")
|
|
47
|
-
else
|
|
48
|
-
value.iso8601
|
|
49
|
-
end
|
|
53
|
+
value.is_a?(::DateTime) ? DateTime.format_datetime_iso8601(value) : value.iso8601
|
|
50
54
|
end
|
|
51
55
|
|
|
52
56
|
# Default XSD type for Date
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -40,10 +40,11 @@ module Lutaml
|
|
|
40
40
|
}
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
-
# Date — ISO8601 with optional timezone
|
|
43
|
+
# Date — ISO8601 with optional timezone; delegates to the
|
|
44
|
+
# resolved type class (subclass serialize overrides fire)
|
|
44
45
|
v.register_format_type_serializer(
|
|
45
46
|
:toml, Lutaml::Model::Type::Date,
|
|
46
|
-
to: ->(inst) {
|
|
47
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
47
48
|
)
|
|
48
49
|
|
|
49
50
|
# TimeWithoutDate — HH:MM:SS.mmm with milliseconds
|
|
@@ -62,22 +62,24 @@ module Lutaml
|
|
|
62
62
|
}
|
|
63
63
|
)
|
|
64
64
|
|
|
65
|
-
# Date — ISO8601 with Z for UTC
|
|
65
|
+
# Date — ISO8601 with Z for UTC. Delegates to the resolved
|
|
66
|
+
# type class so a subclass's own self.serialize override
|
|
67
|
+
# reaches to_xml (issue #1263).
|
|
66
68
|
v.register_format_type_serializer(
|
|
67
69
|
:xml, Lutaml::Model::Type::Date,
|
|
68
70
|
to: lambda { |inst|
|
|
69
71
|
return nil unless inst.value
|
|
70
72
|
|
|
71
|
-
result =
|
|
73
|
+
result = inst.class.serialize(inst.value)
|
|
72
74
|
result = result.sub(/\+00:00$/, "Z") if result.include?("+00:00")
|
|
73
75
|
result
|
|
74
76
|
}
|
|
75
77
|
)
|
|
76
78
|
|
|
77
|
-
# TimeWithoutDate — delegates to
|
|
79
|
+
# TimeWithoutDate — delegates to the resolved type class
|
|
78
80
|
v.register_format_type_serializer(
|
|
79
81
|
:xml, Lutaml::Model::Type::TimeWithoutDate,
|
|
80
|
-
to: ->(inst) {
|
|
82
|
+
to: ->(inst) { inst.class.serialize(inst.value) }
|
|
81
83
|
)
|
|
82
84
|
|
|
83
85
|
# Symbol — :symbol: format
|
|
@@ -25,7 +25,10 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
25
25
|
context "with DateTime object" do
|
|
26
26
|
let(:value) { DateTime.new(2024, 1, 1, 12, 0, 0) }
|
|
27
27
|
|
|
28
|
-
it
|
|
28
|
+
it "keeps the DateTime verbatim (precision preserved)" do
|
|
29
|
+
expect(cast).to eq(value)
|
|
30
|
+
expect(cast.hour).to eq(12)
|
|
31
|
+
end
|
|
29
32
|
end
|
|
30
33
|
|
|
31
34
|
context "with Time object" do
|
|
@@ -58,9 +61,10 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
58
61
|
end
|
|
59
62
|
|
|
60
63
|
it "parses RFC 3339" do
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
result = described_class.cast("2024-01-01T12:00:00Z")
|
|
65
|
+
expect(result).to be_a(DateTime)
|
|
66
|
+
expect(result.hour).to eq(12)
|
|
67
|
+
expect(result.offset).to eq(Rational(0))
|
|
64
68
|
end
|
|
65
69
|
|
|
66
70
|
it "parses common formats" do
|
|
@@ -155,7 +159,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
155
159
|
let(:value) { DateTime.new(2019, 9, 28, 0, 0, 0, Rational(0)) }
|
|
156
160
|
|
|
157
161
|
it "serializes with +00:00 offset" do
|
|
158
|
-
expect(serialize).to eq("2019-09-
|
|
162
|
+
expect(serialize).to eq("2019-09-28T00:00:00+00:00")
|
|
159
163
|
end
|
|
160
164
|
end
|
|
161
165
|
|
|
@@ -163,7 +167,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
163
167
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(8, 24)) }
|
|
164
168
|
|
|
165
169
|
it "serializes with offset" do
|
|
166
|
-
expect(serialize).to eq("2019-12-
|
|
170
|
+
expect(serialize).to eq("2019-12-02T00:00:00+08:00")
|
|
167
171
|
end
|
|
168
172
|
end
|
|
169
173
|
|
|
@@ -171,7 +175,23 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
171
175
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(-5, 24)) }
|
|
172
176
|
|
|
173
177
|
it "serializes with offset" do
|
|
174
|
-
expect(serialize).to eq("2019-12-
|
|
178
|
+
expect(serialize).to eq("2019-12-02T00:00:00-05:00")
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context "with time-of-day (issue #1256)" do
|
|
183
|
+
let(:value) { DateTime.parse("2018-04-15T10:30:00Z") }
|
|
184
|
+
|
|
185
|
+
it "serializes as ISO 8601 dateTime, keeping the time" do
|
|
186
|
+
expect(serialize).to eq("2018-04-15T10:30:00+00:00")
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
context "with fractional seconds" do
|
|
191
|
+
let(:value) { DateTime.parse("2018-04-15T10:30:00.123Z") }
|
|
192
|
+
|
|
193
|
+
it "keeps fractional precision" do
|
|
194
|
+
expect(serialize).to eq("2018-04-15T10:30:00.123+00:00")
|
|
175
195
|
end
|
|
176
196
|
end
|
|
177
197
|
|
|
@@ -191,7 +211,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
191
211
|
let(:value) { DateTime.new(2019, 9, 28, 0, 0, 0, Rational(0)) }
|
|
192
212
|
|
|
193
213
|
it "uses Z notation for UTC" do
|
|
194
|
-
expect(xml_value).to eq("2019-09-
|
|
214
|
+
expect(xml_value).to eq("2019-09-28T00:00:00Z")
|
|
195
215
|
end
|
|
196
216
|
end
|
|
197
217
|
|
|
@@ -199,7 +219,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
199
219
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(8, 24)) }
|
|
200
220
|
|
|
201
221
|
it "uses offset notation" do
|
|
202
|
-
expect(xml_value).to eq("2019-12-
|
|
222
|
+
expect(xml_value).to eq("2019-12-02T00:00:00+08:00")
|
|
203
223
|
end
|
|
204
224
|
end
|
|
205
225
|
|
|
@@ -207,7 +227,15 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
207
227
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(-5, 24)) }
|
|
208
228
|
|
|
209
229
|
it "uses offset notation" do
|
|
210
|
-
expect(xml_value).to eq("2019-12-
|
|
230
|
+
expect(xml_value).to eq("2019-12-02T00:00:00-05:00")
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context "with time-of-day (issue #1256)" do
|
|
235
|
+
let(:value) { DateTime.parse("2010-10-10T12:21:00Z") }
|
|
236
|
+
|
|
237
|
+
it "round-trips the full instant" do
|
|
238
|
+
expect(xml_value).to eq("2010-10-10T12:21:00Z")
|
|
211
239
|
end
|
|
212
240
|
end
|
|
213
241
|
|
|
@@ -227,7 +255,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
227
255
|
let(:value) { DateTime.new(2019, 9, 28, 0, 0, 0, Rational(0)) }
|
|
228
256
|
|
|
229
257
|
it "uses +00:00 notation for UTC" do
|
|
230
|
-
expect(json_value).to eq("2019-09-
|
|
258
|
+
expect(json_value).to eq("2019-09-28T00:00:00+00:00")
|
|
231
259
|
end
|
|
232
260
|
end
|
|
233
261
|
|
|
@@ -235,7 +263,7 @@ RSpec.describe Lutaml::Model::Type::Date do
|
|
|
235
263
|
let(:value) { DateTime.new(2019, 12, 2, 0, 0, 0, Rational(8, 24)) }
|
|
236
264
|
|
|
237
265
|
it "uses offset notation" do
|
|
238
|
-
expect(json_value).to eq("2019-12-
|
|
266
|
+
expect(json_value).to eq("2019-12-02T00:00:00+08:00")
|
|
239
267
|
end
|
|
240
268
|
end
|
|
241
269
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe "Type subclass serialize override" do
|
|
4
|
+
# The documented override pattern: subclass a builtin type and
|
|
5
|
+
# redefine self.serialize. The format-serializer table must resolve
|
|
6
|
+
# to the SUBCLASS's own serialize, not the base class's registered
|
|
7
|
+
# static (issue #1263).
|
|
8
|
+
let(:plain_date) do
|
|
9
|
+
Class.new(Lutaml::Model::Type::Date) do
|
|
10
|
+
def self.cast(value, *)
|
|
11
|
+
value.is_a?(String) ? DateTime.parse(value) : value
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.serialize(value, *)
|
|
15
|
+
return value.strftime("%FT%TZ") if value.is_a?(DateTime)
|
|
16
|
+
|
|
17
|
+
value.iso8601
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
let(:model_class) do
|
|
23
|
+
type = plain_date
|
|
24
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
25
|
+
attribute :begins, type
|
|
26
|
+
|
|
27
|
+
xml do
|
|
28
|
+
root "validity"
|
|
29
|
+
map_element "begins", to: :begins
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
json do
|
|
33
|
+
map "begins", to: :begins
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "xml serialization" do
|
|
39
|
+
it "uses the subclass's serialize override" do
|
|
40
|
+
instance = model_class.new(begins: "2010-10-10T12:21:00Z")
|
|
41
|
+
|
|
42
|
+
expect(instance.to_xml).to eq(<<~XML.strip)
|
|
43
|
+
<validity>
|
|
44
|
+
<begins>2010-10-10T12:21:00Z</begins>
|
|
45
|
+
</validity>
|
|
46
|
+
XML
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "does not fall back to the base Date truncation" do
|
|
50
|
+
instance = model_class.new(begins: "2010-10-10T12:21:00Z")
|
|
51
|
+
|
|
52
|
+
expect(instance.to_xml).not_to include("2010-10-10Z")
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe "json serialization" do
|
|
57
|
+
it "uses the subclass's serialize override" do
|
|
58
|
+
instance = model_class.new(begins: "2010-10-10T12:21:00Z")
|
|
59
|
+
|
|
60
|
+
expect(instance.to_json).to include('"begins":"2010-10-10T12:21:00Z"')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "base-class behavior is unchanged" do
|
|
65
|
+
let(:base_model_class) do
|
|
66
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
67
|
+
attribute :begins, Lutaml::Model::Type::Date
|
|
68
|
+
|
|
69
|
+
xml do
|
|
70
|
+
root "validity"
|
|
71
|
+
map_element "begins", to: :begins
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "serializes a plain Date as xs:date" do
|
|
77
|
+
instance = base_model_class.new(begins: "2010-10-10")
|
|
78
|
+
|
|
79
|
+
expect(instance.to_xml).to eq(<<~XML.strip)
|
|
80
|
+
<validity>
|
|
81
|
+
<begins>2010-10-10</begins>
|
|
82
|
+
</validity>
|
|
83
|
+
XML
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
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.8.
|
|
4
|
+
version: 0.8.194
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -2194,6 +2194,7 @@ files:
|
|
|
2194
2194
|
- spec/lutaml/model/type/reference_integration_spec.rb
|
|
2195
2195
|
- spec/lutaml/model/type/reference_spec.rb
|
|
2196
2196
|
- spec/lutaml/model/type/string_spec.rb
|
|
2197
|
+
- spec/lutaml/model/type/subclass_serialize_override_spec.rb
|
|
2197
2198
|
- spec/lutaml/model/type/symbol_spec.rb
|
|
2198
2199
|
- spec/lutaml/model/type/time_spec.rb
|
|
2199
2200
|
- spec/lutaml/model/type/time_without_date_spec.rb
|