lutaml-model 0.8.143 → 0.8.144
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: ff4c24c792fe315c6798bf64b67dbc4924fc919fc447e4a0264467d169a80315
|
|
4
|
+
data.tar.gz: 15621c39ad1d06dddbca3c9b0ef809b1a87d13222ef850c0cdb557da3317ca1d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21de2545ba67ce8357cd0216e70a085648ea24153cff022a805005b677d7d90ab51af50869cfc6335d6aad5404f4bb4fde30ed9f6389a31ff9b7ac51580646b4
|
|
7
|
+
data.tar.gz: d46faf8a708c88622abb2d560bf2f533da86815553c81049b8d432f71d60cfad67a65e567858454a7ecad721b2d2e02c2c3d6bd8bc173416903dc5d4faab7065
|
|
@@ -184,12 +184,16 @@ module Lutaml
|
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
-
private
|
|
188
|
-
|
|
189
187
|
# Replace a shared structure with a class-owned copy. The copy
|
|
190
188
|
# becomes the snapshot for every existing subclass, which is what
|
|
191
189
|
# keeps post-fork mutations invisible to them (the eager-copy
|
|
192
190
|
# semantics).
|
|
191
|
+
#
|
|
192
|
+
# Public on purpose: code that mutates `mappings`, `attributes`,
|
|
193
|
+
# `choices` or `registers` outside the DSL — sibling classes pruning
|
|
194
|
+
# inherited elements (relaton's Item-header prunes) or importing
|
|
195
|
+
# models — must fork the structure first, or the mutation lands on
|
|
196
|
+
# the object shared with the superclass and every sibling class.
|
|
193
197
|
def lutaml_cow_fork!(structure)
|
|
194
198
|
return if lutaml_cow_status(structure) == 1
|
|
195
199
|
|
|
@@ -220,8 +224,6 @@ module Lutaml
|
|
|
220
224
|
lutaml_cow_set_status!(structure, 1)
|
|
221
225
|
end
|
|
222
226
|
|
|
223
|
-
public
|
|
224
|
-
|
|
225
227
|
# Return the mapping object a format DSL may mutate. Forking
|
|
226
228
|
# the mappings structure copies every entry, so the object
|
|
227
229
|
# returned here is this class's own.
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# Copy-on-write inheritance shares a subclass's structures with its
|
|
6
|
+
# superclass until the class's own DSL forks them. External mutators — a
|
|
7
|
+
# library pruning an inherited attribute on one subclass (relaton's
|
|
8
|
+
# Item-header prunes) — need a supported way to claim ownership first, or
|
|
9
|
+
# the mutation erases the attribute for every sibling class.
|
|
10
|
+
RSpec.describe "Lutaml::Model::Serializable#lutaml_cow_fork!" do
|
|
11
|
+
let(:parent_class) do
|
|
12
|
+
Class.new(Lutaml::Model::Serializable) do
|
|
13
|
+
attribute :id, :string
|
|
14
|
+
attribute :shared, :string
|
|
15
|
+
|
|
16
|
+
xml do
|
|
17
|
+
root "parent"
|
|
18
|
+
map_attribute "id", to: :id
|
|
19
|
+
map_element "shared", to: :shared
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:child_class) do
|
|
25
|
+
Class.new(parent_class)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "is callable from outside the DSL" do
|
|
29
|
+
expect(child_class).to respond_to(:lutaml_cow_fork!)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "gives the class a private copy without touching the superclass" do
|
|
33
|
+
parent_attributes = parent_class.class_attributes
|
|
34
|
+
child_class.lutaml_cow_fork!(:attributes)
|
|
35
|
+
|
|
36
|
+
expect(child_class.class_attributes).not_to equal(parent_attributes)
|
|
37
|
+
expect(parent_class.class_attributes).to equal(parent_attributes)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "keeps post-fork mutations private to the forking class" do
|
|
41
|
+
child_class.lutaml_cow_fork!(:attributes)
|
|
42
|
+
child_class.lutaml_cow_fork!(:mappings)
|
|
43
|
+
child_class.class_attributes.delete(:id)
|
|
44
|
+
xml_attrs = child_class.mappings[:xml].instance_variable_get(:@attributes)
|
|
45
|
+
xml_attrs.delete("id")
|
|
46
|
+
|
|
47
|
+
expect(parent_class.class_attributes).to be_key(:id)
|
|
48
|
+
expect(parent_class.mappings[:xml]
|
|
49
|
+
.instance_variable_get(:@attributes)).to be_key("id")
|
|
50
|
+
expect(child_class.class_attributes).not_to be_key(:id)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "does not fork an already-owned structure into a new object" do
|
|
54
|
+
child_class.lutaml_cow_fork!(:attributes)
|
|
55
|
+
owned = child_class.class_attributes
|
|
56
|
+
child_class.lutaml_cow_fork!(:attributes)
|
|
57
|
+
|
|
58
|
+
expect(child_class.class_attributes).to equal(owned)
|
|
59
|
+
end
|
|
60
|
+
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.144
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -1753,6 +1753,7 @@ files:
|
|
|
1753
1753
|
- spec/lutaml/model/consolidation_spec.rb
|
|
1754
1754
|
- spec/lutaml/model/context_registry_spec.rb
|
|
1755
1755
|
- spec/lutaml/model/conversion_caching_spec.rb
|
|
1756
|
+
- spec/lutaml/model/cow_fork_public_spec.rb
|
|
1756
1757
|
- spec/lutaml/model/custom_bibtex_adapter_spec.rb
|
|
1757
1758
|
- spec/lutaml/model/custom_collection_spec.rb
|
|
1758
1759
|
- spec/lutaml/model/custom_from_empty_values_spec.rb
|