lutaml-model 0.8.108 → 0.8.109
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: 45a348d47b61525553682dc4a12be7cde6239ba3d8367e1338e8a266c59ad806
|
|
4
|
+
data.tar.gz: 1a3816081d045d022bf6fcb94a6a82bdfe335644bdbc925d3bcf7676522b433c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b0e82b390f6d56ae98f9f98c9c16b121e8c96290cb79c8db0c31723104a0e940d4bfe798f3facee8493b2257f47c4597b91920cf6dff93dfa89e0875970746b
|
|
7
|
+
data.tar.gz: c5e85f1a1a613112a08795db1e299bfda7ba41057091da39e371f24d03759ff739f56ad96b929c7d41b50ecd4bbbf41f87543205e850239c6494d89f3d334398
|
|
@@ -398,11 +398,27 @@ module Lutaml
|
|
|
398
398
|
# cast_items already returns a fresh array, so the plain-Array
|
|
399
399
|
# collection needs no re-wrap — build_collection's
|
|
400
400
|
# collection_class.new would copy it again.
|
|
401
|
+
assert_flat_collection_items!(items)
|
|
401
402
|
return items if !custom_collection? && collection_class == ::Array
|
|
402
403
|
|
|
403
404
|
build_collection(items, register: register)
|
|
404
405
|
end
|
|
405
406
|
|
|
407
|
+
# Fail loudly on nested arrays. A collection's declared element
|
|
408
|
+
# type never admits an Array as an item; the legacy
|
|
409
|
+
# build_collection flatten silently absorbed mis-spliced builder
|
|
410
|
+
# output (expressir#506 surfaced it three frames away in a
|
|
411
|
+
# formatter). The error must land at the assignment boundary.
|
|
412
|
+
def assert_flat_collection_items!(items)
|
|
413
|
+
return unless items.any?(::Array)
|
|
414
|
+
|
|
415
|
+
raise TypeError,
|
|
416
|
+
"collection '#{name}': item " \
|
|
417
|
+
"#{items.index { |item| item.is_a?(::Array) }} is an Array " \
|
|
418
|
+
"where the declared element type is expected; nested arrays " \
|
|
419
|
+
"are not flattened — splice list results before assignment"
|
|
420
|
+
end
|
|
421
|
+
|
|
406
422
|
# Plain Arrays count as list input. On singular attributes
|
|
407
423
|
# collection_instance? matches Arrays too (their collection class is
|
|
408
424
|
# Array), preserving the Array so strict cardinality can flag it.
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "strict collection assignment" do
|
|
6
|
+
let(:node_class) do
|
|
7
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
8
|
+
attribute :id, :string
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:holder_class) do
|
|
13
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
14
|
+
attribute :items, "Node", collection: true
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
stub_const("Node", node_class)
|
|
20
|
+
stub_const("Holder", holder_class)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "raises at the constructor boundary" do
|
|
24
|
+
expect do
|
|
25
|
+
Holder.new(items: [[Node.new(id: "a")], Node.new(id: "b")])
|
|
26
|
+
end.to raise_error(Lutaml::Model::TypeError, /item 0 is an Array/)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "raises at the writer boundary" do
|
|
30
|
+
holder = Holder.new
|
|
31
|
+
expect do
|
|
32
|
+
holder.items = [Node.new, [Node.new]]
|
|
33
|
+
end.to raise_error(Lutaml::Model::TypeError, /item 1 is an Array/)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "raises for a custom collection class" do
|
|
37
|
+
custom = Class.new(Lutaml::Model::Collection) do
|
|
38
|
+
instances :node, "Node"
|
|
39
|
+
end
|
|
40
|
+
stub_const("NodeBag", custom)
|
|
41
|
+
wrapper = Class.new(Lutaml::Model::Serializable) do
|
|
42
|
+
attribute :bag, "NodeBag"
|
|
43
|
+
end
|
|
44
|
+
stub_const("BagHolder", wrapper)
|
|
45
|
+
|
|
46
|
+
expect do
|
|
47
|
+
BagHolder.new(bag: [[Node.new]])
|
|
48
|
+
end.to raise_error(Lutaml::Model::TypeError, /nested arrays are not flattened/)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "keeps flat assignment untouched" do
|
|
52
|
+
holder = Holder.new(items: [Node.new(id: "x")])
|
|
53
|
+
expect(holder.items.map(&:id)).to eq(["x"])
|
|
54
|
+
end
|
|
55
|
+
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.109
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -1724,6 +1724,7 @@ files:
|
|
|
1724
1724
|
- spec/lutaml/model/collection_single_value_coercion_spec.rb
|
|
1725
1725
|
- spec/lutaml/model/collection_spec.rb
|
|
1726
1726
|
- spec/lutaml/model/collection_state_nesting_spec.rb
|
|
1727
|
+
- spec/lutaml/model/collection_strict_assignment_spec.rb
|
|
1727
1728
|
- spec/lutaml/model/collection_validation_spec.rb
|
|
1728
1729
|
- spec/lutaml/model/comparable_model_spec.rb
|
|
1729
1730
|
- spec/lutaml/model/comparison_family_spec.rb
|