lutaml-model 0.8.190 → 0.8.191
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e7b10a03d458c7802e12b80ba1dd59ed0d4f4c75668a69c13d9add36f3722ba
|
|
4
|
+
data.tar.gz: 3a8bee4fcd326b8dd9d1ecded4c7e285f35792cd41d03cc01aa67b3fbc0970e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 353c5e1fbb2e53f1f4013f0d8e33b72aa345dfc29c98ce306060233f97a1403bf978bfeef4bf8d03fb0318758ac3a4e0d47fb1bc614662a2a6be4f65b687b50f
|
|
7
|
+
data.tar.gz: 57aca3cc29495f7418d9d8c31932c5655359448ae54c8480177c577f26bd9f971a19787b2deaab7929cb8411cf3f254cc85290d2db81b523bd0a56475c3b74b1
|
|
@@ -643,17 +643,12 @@ module Lutaml
|
|
|
643
643
|
return resolved_type.new(value)
|
|
644
644
|
end
|
|
645
645
|
|
|
646
|
-
# A plain scalar for a mapped complex attribute
|
|
647
|
-
#
|
|
648
|
-
#
|
|
649
|
-
#
|
|
650
|
-
#
|
|
651
|
-
#
|
|
652
|
-
if value.is_a?(::String) && !hash_type? &&
|
|
653
|
-
resolved_type.include?(Lutaml::Model::Serialize)
|
|
654
|
-
content_attr = scalar_content_attribute_for(resolved_type)
|
|
655
|
-
return resolved_type.new(content_attr => value) if content_attr
|
|
656
|
-
end
|
|
646
|
+
# A plain scalar for a mapped complex attribute does NOT coerce
|
|
647
|
+
# here: this method is shared with direct construction
|
|
648
|
+
# (Model.new), where an assigned String must keep verbatim
|
|
649
|
+
# (the 0.8.x contract — #1252). The scalar-coercion contract
|
|
650
|
+
# (#1228: `title: "Coll"` builds the localized title) lives
|
|
651
|
+
# solely at the format boundary — see cast_present.
|
|
657
652
|
|
|
658
653
|
# Special handling for Reference types - pass the metadata
|
|
659
654
|
# (the comparison is attribute-constant; memoize the verdict)
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# lutaml-model#1252: direct construction must keep an assigned String
|
|
6
|
+
# verbatim, even when the declared type is a Serializable whose
|
|
7
|
+
# (derived or explicit) mapping exposes a scalar `content` rule. The
|
|
8
|
+
# scalar-coercion contract (#1228, #978) belongs to the format
|
|
9
|
+
# boundary (from_json/from_yaml/from_hash) only.
|
|
10
|
+
RSpec.describe "direct construction keeps assigned scalars verbatim" do
|
|
11
|
+
let(:text_element_class) do
|
|
12
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
13
|
+
attribute :content, Lutaml::Model::Serializable, default: -> { "" },
|
|
14
|
+
polymorphic: [Lutaml::Model::Type::String, :array]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
let(:title_class) do
|
|
19
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
20
|
+
attribute :content, "VerbatimTextElement"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
before do
|
|
25
|
+
stub_const("VerbatimTextElement", text_element_class)
|
|
26
|
+
stub_const("VerbatimTitle", title_class)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# The ceradoc shape: derived mapping, polymorphic inner content.
|
|
30
|
+
it "keeps the String with a derived content mapping (#1252)" do
|
|
31
|
+
title = VerbatimTitle.new(content: "Test Document")
|
|
32
|
+
|
|
33
|
+
expect(title.content).to be_a(String)
|
|
34
|
+
expect(title.content).to eq("Test Document")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "keeps the String with an explicit keyed content mapping" do
|
|
38
|
+
element_class = Class.new(Lutaml::Model::Serializable) do
|
|
39
|
+
attribute :content, :string
|
|
40
|
+
|
|
41
|
+
key_value do
|
|
42
|
+
map "content", to: :content
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
stub_const("VerbatimMappedElement", element_class)
|
|
46
|
+
|
|
47
|
+
holder = Class.new(Lutaml::Model::Serializable) do
|
|
48
|
+
attribute :body, "VerbatimMappedElement"
|
|
49
|
+
end
|
|
50
|
+
stub_const("VerbatimMappedHolder", holder)
|
|
51
|
+
|
|
52
|
+
model = VerbatimMappedHolder.new(body: "plain text")
|
|
53
|
+
|
|
54
|
+
expect(model.body).to be_a(String)
|
|
55
|
+
expect(model.body).to eq("plain text")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "still coerces at the deserialization boundary (#1228 contract)" do
|
|
59
|
+
element_class = Class.new(Lutaml::Model::Serializable) do
|
|
60
|
+
attribute :content, :string
|
|
61
|
+
|
|
62
|
+
key_value do
|
|
63
|
+
map "content", to: :content
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
stub_const("BoundaryMappedElement", element_class)
|
|
67
|
+
|
|
68
|
+
holder = Class.new(Lutaml::Model::Serializable) do
|
|
69
|
+
attribute :body, "BoundaryMappedElement"
|
|
70
|
+
|
|
71
|
+
key_value do
|
|
72
|
+
map "body", to: :body
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
stub_const("BoundaryHolder", holder)
|
|
76
|
+
|
|
77
|
+
model = BoundaryHolder.from_json('{"body": "wire text"}')
|
|
78
|
+
|
|
79
|
+
expect(model.body).to be_a(BoundaryMappedElement)
|
|
80
|
+
expect(model.body.content).to eq("wire text")
|
|
81
|
+
end
|
|
82
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.191
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -2087,6 +2087,7 @@ files:
|
|
|
2087
2087
|
- spec/lutaml/model/delegation_spec.rb
|
|
2088
2088
|
- spec/lutaml/model/derived_attribute_serialization_spec.rb
|
|
2089
2089
|
- spec/lutaml/model/desc_spec.rb
|
|
2090
|
+
- spec/lutaml/model/direct_construction_verbatim_spec.rb
|
|
2090
2091
|
- spec/lutaml/model/dynamic_attribute_spec.rb
|
|
2091
2092
|
- spec/lutaml/model/encoding_spec.rb
|
|
2092
2093
|
- spec/lutaml/model/enum_spec.rb
|