lutaml-model 0.8.200 → 0.8.201

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: 9a7958849b1b037485644838e6cd7b3264546a8f25fdfd8d29d694595fb2c4be
4
- data.tar.gz: 16e38f14e5d3c06b55073d626dcf79e8fb93f33c1775bf2ef2288d62d614c617
3
+ metadata.gz: '0499659ca4f9da568095087ed451503ced3992c62bf056b06bd268398cb2a609'
4
+ data.tar.gz: cf53f475ba4d0e0d6d7dc0ced4793e0f9a07e09b585113cf4fa1c8b81c517bcf
5
5
  SHA512:
6
- metadata.gz: 290f49e6e4d3801291845ffd8ef58822363f70fdc8a8ee17013757a5a5afc3b10ff73187bf75a8e11a20271750534f3e6c0b888569dc1f81f71db12e36d906b9
7
- data.tar.gz: 2df50e5220736a2d7468cd5ae6713e819cce37bfcfaacf7c7248901db6f31023d01a92015f7dd1bbb02db1876f66b9def21ea2309de15414f777d714227aeb15
6
+ metadata.gz: 17890881efe1ae3bdf15c996b1da9bf660932cef57abc3ca0f6f87a584e3150d12b9615435ae1151864cb8f6ee4711f47bed27cd7b450723cfb7f820ead542c7
7
+ data.tar.gz: 6b7e93f724efba2c00fd528b94a34f465bd8bcd8e49b64a7e41fb741e9395b59635454090ff94867a101d3da7233114c77fb2a79da17716f3307c8d6b8f106d8
@@ -1709,6 +1709,10 @@ instance_object = nil)
1709
1709
  def valid_polymorphic_type?(value)
1710
1710
  return value.is_a?(type) unless has_polymorphic_list?
1711
1711
 
1712
+ # A list of String names alone restricts nothing beyond the
1713
+ # declared base: the names are never resolved (#1306).
1714
+ return value.is_a?(type) if polymorphic_names_only?
1715
+
1712
1716
  return true if polymorphic_scalar_member?(value)
1713
1717
  return false unless value.is_a?(Serialize)
1714
1718
 
@@ -1719,12 +1723,15 @@ instance_object = nil)
1719
1723
 
1720
1724
  # Definition-time contract for the polymorphic list: an entry that can
1721
1725
  # never match anything — a Symbol other than :array — fails the
1722
- # declaration instead of surfacing at serialization (#1292).
1726
+ # declaration instead of surfacing at serialization (#1292). A String
1727
+ # is the lazy type-name form a String attribute type takes; its class
1728
+ # may not be loaded at declaration time, so it is accepted here and
1729
+ # the list never resolves it (#1306).
1723
1730
  def validate_polymorphic_entries!(entries)
1724
1731
  return unless entries.is_a?(Array)
1725
1732
 
1726
1733
  entries.each do |entry|
1727
- next if entry.is_a?(Class) || entry == :array
1734
+ next if entry.is_a?(Class) || entry.is_a?(String) || entry == :array
1728
1735
 
1729
1736
  raise ArgumentError,
1730
1737
  "polymorphic entry #{entry.inspect} is not a type: use a " \
@@ -1735,6 +1742,11 @@ instance_object = nil)
1735
1742
  def has_polymorphic_list?
1736
1743
  options[:polymorphic]&.is_a?(Array)
1737
1744
  end
1745
+
1746
+ def polymorphic_names_only?
1747
+ list = options[:polymorphic]
1748
+ list.any?(String) && list.none?(Class)
1749
+ end
1738
1750
  end
1739
1751
  end
1740
1752
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.200"
5
+ VERSION = "0.8.201"
6
6
  end
7
7
  end
@@ -110,4 +110,61 @@ RSpec.describe "polymorphic scalar members under a Serializable base" do
110
110
  end.to raise_error(ArgumentError, /polymorphic entry :frobnicate is not a type/)
111
111
  end
112
112
  end
113
+
114
+ # lutaml-model#1306: a String entry is the lazy type-name form, as for
115
+ # a String attribute type (fontist 3.0.45 lists its import sources by
116
+ # name). The list never resolves names, so they restrict nothing
117
+ # beyond the declared base — the behavior before 0.8.199, which must
118
+ # stay: a working declaration may not start failing at require time.
119
+ describe "String entries" do
120
+ let(:name_base_class) do
121
+ Class.new(Lutaml::Model::Serializable) do
122
+ attribute :x, :string
123
+
124
+ json { map :x, to: :x }
125
+ end
126
+ end
127
+
128
+ let(:named_list_class) do
129
+ base = name_base_class
130
+ Class.new(Lutaml::Model::Serializable) do
131
+ attribute :source, base, polymorphic: [
132
+ "MacosImportSource",
133
+ "GoogleImportSource",
134
+ "SilImportSource",
135
+ ]
136
+
137
+ json { map :source, to: :source }
138
+ end
139
+ end
140
+
141
+ before do
142
+ stub_const("PolyNameBase", name_base_class)
143
+ stub_const("PolyNamedList", named_list_class)
144
+ end
145
+
146
+ it "accepts a name at class definition" do
147
+ expect { PolyNamedList }.not_to raise_error
148
+ end
149
+
150
+ it "keeps a list of names inert: the declared base governs" do
151
+ model = PolyNamedList.new(source: PolyNameBase.new(x: "v"))
152
+ expect(model.validate).to eq([])
153
+ expect(model.to_json).to eq('{"source":{"x":"v"}}')
154
+ expect(PolyNamedList.from_json(model.to_json).source).to be_a(PolyNameBase)
155
+ end
156
+
157
+ it "keeps the class entries authoritative beside a name" do
158
+ member = model_member_class
159
+ other = Class.new(Lutaml::Model::Serializable) { attribute :y, :integer }
160
+ stub_const("PolyOtherMember", other)
161
+ mixed = Class.new(Lutaml::Model::Serializable) do
162
+ attribute :content, Lutaml::Model::Serializable, polymorphic: [member, "OtherMember"]
163
+ end
164
+
165
+ expect(mixed.new(content: member.new(x: "v")).validate).to eq([])
166
+ expect(mixed.new(content: other.new(y: 1)).validate.first)
167
+ .to be_a(Lutaml::Model::PolymorphicError)
168
+ end
169
+ end
113
170
  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.200
4
+ version: 0.8.201
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.