lutaml-model 0.8.144 → 0.8.145
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/model/serialize/value_mapping.rb +15 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/spec/lutaml/model/polymorphic_spec.rb +28 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1d4a991baea8734712513f2d1ffb0025d0a5867f174a40b32bee58b1be5017c5
|
|
4
|
+
data.tar.gz: f1713d5b0ef5024da66ee23f8251604da86fd3f8d7035e7f64118bf080ea9128
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db827973c88ea9fe1779a0105d18ef1d0f93868fa4a59147a029c504005ec5f5e50378a7f90c490097e24d20c62fb33531a8fe277fb7620ed3cd17debdd2adaf
|
|
7
|
+
data.tar.gz: 90045bda2ce6c2605ca3708527c44ad7811cacb6cb8d4f72d83f3a875a3a043a84503dc48f24f716d94f5e92e367d6a4bfb2fa556982d14db65125623d885252
|
|
@@ -67,6 +67,21 @@ module Lutaml
|
|
|
67
67
|
klass = Object.const_get(klass_name)
|
|
68
68
|
|
|
69
69
|
propagated = options.slice(*Lutaml::Model::Attribute::CHILD_PROPAGATION_KEYS)
|
|
70
|
+
|
|
71
|
+
# A map entry that resolves to the deserializing class itself
|
|
72
|
+
# (a subclass inheriting its base's map, or an apply_mappings
|
|
73
|
+
# override delegating back to super for its own concrete class)
|
|
74
|
+
# must fall through to this class's real deserialization:
|
|
75
|
+
# re-dispatching apply_mappings would resolve the same entry
|
|
76
|
+
# again and never make progress.
|
|
77
|
+
if klass == model
|
|
78
|
+
transformer = Lutaml::Model::Config.transformer_for(format)
|
|
79
|
+
return transformer.data_to_model(
|
|
80
|
+
self, doc, format,
|
|
81
|
+
propagated.merge(register: instance.lutaml_register)
|
|
82
|
+
)
|
|
83
|
+
end
|
|
84
|
+
|
|
70
85
|
klass.apply_mappings(doc, format,
|
|
71
86
|
propagated.merge(register: instance.lutaml_register))
|
|
72
87
|
end
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -125,6 +125,21 @@ module PolymorphicSpec
|
|
|
125
125
|
}
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
|
+
|
|
129
|
+
# A polymorphic map whose entry resolves to the class carrying it
|
|
130
|
+
# (e.g. a subclass inheriting its base's map, or an apply_mappings
|
|
131
|
+
# override delegating back to super for its own concrete class).
|
|
132
|
+
class SelfResolving < Lutaml::Model::Serializable
|
|
133
|
+
attribute :_type, :string
|
|
134
|
+
attribute :name, :string
|
|
135
|
+
|
|
136
|
+
key_value do
|
|
137
|
+
map "_type", to: :_type, polymorphic_map: {
|
|
138
|
+
"self_resolving" => "PolymorphicSpec::Base::SelfResolving",
|
|
139
|
+
}
|
|
140
|
+
map "name", to: :name
|
|
141
|
+
end
|
|
142
|
+
end
|
|
128
143
|
end
|
|
129
144
|
|
|
130
145
|
module Child
|
|
@@ -546,4 +561,17 @@ RSpec.describe "Polymorphic" do
|
|
|
546
561
|
end
|
|
547
562
|
end
|
|
548
563
|
end
|
|
564
|
+
|
|
565
|
+
# A polymorphic map that resolves a document to the very class that is
|
|
566
|
+
# deserializing it must fall through to the model's own
|
|
567
|
+
# deserialization, not re-dispatch apply_mappings forever.
|
|
568
|
+
context "when the polymorphic map resolves to the deserializing class" do
|
|
569
|
+
it "deserializes without recursing" do
|
|
570
|
+
model = PolymorphicSpec::Base::SelfResolving.apply_mappings(
|
|
571
|
+
{ "_type" => "self_resolving", "name" => "x" }, :hash
|
|
572
|
+
)
|
|
573
|
+
expect(model).to be_a(PolymorphicSpec::Base::SelfResolving)
|
|
574
|
+
expect(model.name).to eq("x")
|
|
575
|
+
end
|
|
576
|
+
end
|
|
549
577
|
end
|