moxml 0.5.42 → 0.5.43

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: d447f74ea4b1c546e83fbb94819c6043a1fa48e0f9932ac7202009cecff63e1e
4
- data.tar.gz: 4c33c0af41d9c628ecc993d7015d4e827d1d451b266dd7ad4145f00b322670a3
3
+ metadata.gz: 0c8fd5df5889694c9d7a3ee99c4caad866ddc40edd13ba46945f55e4e9f77a9b
4
+ data.tar.gz: ce14f6e9199e22576c0c5149e716a672efb9e44ef3a9b68d1b78abad02754a92
5
5
  SHA512:
6
- metadata.gz: ebdc376975c3893facd06d793a04eebdfa9387814b131b9f0c5aecbd047fb57dcfadba80c40eee8ff60e52b4a7cbf1e886e67909b5f9b46623ca91b75cdb04b5
7
- data.tar.gz: 9cf48a7154d6336a24504df0ec1cd62d689859f1b8f9df85e313bf69f1db97a17191e813b7f2e10bdd8565644dae88f6b323b1cd109e64995e26ea8d537bb67a
6
+ metadata.gz: 93ac1cd541ed454ac89c10179e5e56f919a4cd309ae8f16abe02950ea5a6fedfdb03c53a7a8c23520616cd202a2b8f5384616ac8cd7b9e884d9f127c1d38bd98
7
+ data.tar.gz: ed75757fec960bd181921f9562650f4f3d44f2261fa0eb41a09437906d26581ad07c8b5446d0719a1d26b5308de2e1e25c60d2f0013da6861d144692d53eada4
@@ -89,7 +89,17 @@ module Moxml
89
89
  # sites must never depend on the layer having loaded
90
90
  # (issue #217 — binding-only installs crashed on the
91
91
  # unguarded bridges).
92
+ # Class-body level: a bare @ivar inside `class << self` lands
93
+ # on the singleton's singleton, invisible to the methods at
94
+ # call time (same shape as @native_doc_roots below).
95
+ @binding_of = ObjectSpace::WeakMap.new
96
+
92
97
  class << self
98
+ # native -> bridged binding node. The bridge object is
99
+ # identity-stable for the native's lifetime (the binding's
100
+ # per-document wrap cache), so repeat bridges — the write
101
+ # loop on a factory-created element, re-accessed attribute
102
+ # lists — skip the document resolution and pointer wrap.
93
103
  # Binding node for any native: identity for binding nodes
94
104
  # (and on installs without the native layer — the constant
95
105
  # check short-circuits), a Node.wrap over the shared C
@@ -98,11 +108,14 @@ module Moxml
98
108
  return node unless NATIVE_READ_LAYER &&
99
109
  node.is_a?(::Leptris::XML::NativeNode)
100
110
 
111
+ bridged = @binding_of[node]
112
+ return bridged if bridged
113
+
101
114
  doc = doc_for(node)
102
115
  ptr = ::FFI::Pointer.new(node.address)
103
- return ::Leptris::XML::Node.wrap(ptr, doc) if doc
104
-
105
- ::Leptris::XML::Node.wrap(ptr, nil)
116
+ bridged = ::Leptris::XML::Node.wrap(ptr, doc)
117
+ @binding_of[node] = bridged unless bridged.nil?
118
+ bridged
106
119
  end
107
120
  end
108
121
 
@@ -281,7 +294,7 @@ module Moxml
281
294
  end
282
295
 
283
296
  def set_root(doc, element)
284
- doc.root = element
297
+ to_binding(doc).root = to_binding(element)
285
298
  end
286
299
 
287
300
  def bare_set_qname_safe?
@@ -140,6 +140,7 @@ module Moxml
140
140
  end
141
141
 
142
142
  def set_root(doc, element)
143
+ doc.delete_element(doc.root) if doc.root
143
144
  doc.add_element(element)
144
145
  end
145
146
 
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.5.42"
4
+ VERSION = "0.5.43"
5
5
  end
@@ -143,4 +143,38 @@ RSpec.shared_examples "Moxml Integration" do
143
143
  )
144
144
  end
145
145
  end
146
+
147
+ describe "document root assignment" do
148
+ it "attaches a factory-created element as the root and serializes" do
149
+ doc = context.create_document
150
+ root = doc.create_element("root")
151
+ root["id"] = "1"
152
+ child = doc.create_element("child")
153
+ child.text = "data"
154
+ root.add_child(child)
155
+
156
+ doc.root = root
157
+
158
+ expect(doc.root.name).to eq("root")
159
+ expect(doc.root["id"]).to eq("1")
160
+ expect(doc.root.parent).to eq(doc)
161
+ expect(doc.to_xml).to include("<root id=\"1\">", "<child>data</child>")
162
+
163
+ reparsed = context.parse(doc.to_xml)
164
+ expect(reparsed.root["id"]).to eq("1")
165
+ expect(reparsed.at_xpath("//child").text).to eq("data")
166
+ end
167
+
168
+ it "replaces an existing root" do
169
+ doc = context.parse("<old><nested/></old>")
170
+ replacement = doc.create_element("new")
171
+ replacement.add_child("text")
172
+
173
+ doc.root = replacement
174
+
175
+ expect(doc.root.name).to eq("new")
176
+ expect(doc.to_xml).to include("<new>text</new>")
177
+ expect(doc.to_xml).not_to include("old")
178
+ end
179
+ end
146
180
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.42
4
+ version: 0.5.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.