moxml 0.6.7 → 0.6.9
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/moxml/adapter/leptris.rb +81 -4
- data/lib/moxml/version.rb +1 -1
- data/spec/moxml/adapter/leptris_registered_subclass_spec.rb +74 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cc0dda0f9bbdf4fb0a15c838dfc7473b449e748b89a06297251b8eca26fc1b00
|
|
4
|
+
data.tar.gz: 7ed72ebaab1c2314a15bde5fcc28c1faa972505d18ad2377aaddaf6d6ba3e7a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 60fb29b4a82b964bc1021ab7eeb1f632ab36535ad59f1b546bc6562d46b41fd6e1ef1a92906ff1010bc0f3520fd2aa871a503f7b327e64d8c2852c9611504a48
|
|
7
|
+
data.tar.gz: c388f5f4f58a8e357c736d4cb23afe08b241c007207e70e13f3589baa10341eed4d2da77e6d46e54ccd81da2ded30aa3fd5d935f0d8464b6f6d3b4c334fff3ca
|
|
@@ -1097,8 +1097,31 @@ module Moxml
|
|
|
1097
1097
|
# IS the wrapper. Prime in place with a self-marker
|
|
1098
1098
|
# (never a shell, never the WeakMap round trip).
|
|
1099
1099
|
if NATIVE_C_MINT && node.is_a?(::Moxml::Node)
|
|
1100
|
+
# #340 admits ANY NativeNode subclass as a registered
|
|
1101
|
+
# wrapper klass, and consumers register their own
|
|
1102
|
+
# (define_hot_readers subclasses, leptris-ruby#629) —
|
|
1103
|
+
# the exact-class hash answers only the Identity
|
|
1104
|
+
# originals, so a subclass minted nil here and every
|
|
1105
|
+
# walk-yielded node dropped from results (XPath
|
|
1106
|
+
# answered zero rows with subclasses registered).
|
|
1107
|
+
# Resolve the kind subclass-aware; the hash still
|
|
1108
|
+
# serves the exact originals without the ladder.
|
|
1100
1109
|
type = IDENTITY_WALK_TYPE[node.class]
|
|
1101
|
-
|
|
1110
|
+
unless type
|
|
1111
|
+
type = case node
|
|
1112
|
+
when Identity::ELEMENT
|
|
1113
|
+
:element
|
|
1114
|
+
when Identity::TEXT
|
|
1115
|
+
:text
|
|
1116
|
+
when Identity::CDATA
|
|
1117
|
+
:cdata
|
|
1118
|
+
when Identity::COMMENT
|
|
1119
|
+
:comment
|
|
1120
|
+
when Identity::PROCESSING_INSTRUCTION
|
|
1121
|
+
:processing_instruction
|
|
1122
|
+
end
|
|
1123
|
+
return nil unless type
|
|
1124
|
+
end
|
|
1102
1125
|
|
|
1103
1126
|
node.prime_contract(node, context, self, type)
|
|
1104
1127
|
node.instance_variable_set(:@moxml_wrapper, node)
|
|
@@ -1763,7 +1786,9 @@ module Moxml
|
|
|
1763
1786
|
"(empty or whitespace-only input)"]
|
|
1764
1787
|
end
|
|
1765
1788
|
|
|
1766
|
-
register_mint_klasses!(
|
|
1789
|
+
register_mint_klasses!(
|
|
1790
|
+
native_doc, hot: !entity_markers && !entity_mode_keep
|
|
1791
|
+
)
|
|
1767
1792
|
ctx = _context || Context.new(:leptris)
|
|
1768
1793
|
doc = Wrappers::Document.new(native_doc, ctx)
|
|
1769
1794
|
|
|
@@ -2084,10 +2109,62 @@ module Moxml
|
|
|
2084
2109
|
[].freeze
|
|
2085
2110
|
end
|
|
2086
2111
|
|
|
2087
|
-
|
|
2112
|
+
# The hot klass variants (TODO.perf/39(a), leptris-ruby#627):
|
|
2113
|
+
# define_hot_readers installs the C readers (name/content)
|
|
2114
|
+
# directly on the subclass, so lookup answers in C with no
|
|
2115
|
+
# contract-module shadow. The C bodies must not shadow
|
|
2116
|
+
# contract semantics: `attribute` answers the value string
|
|
2117
|
+
# (the contract returns the attribute object) and `name` is
|
|
2118
|
+
# element-shaped (non-element contracts shape it), so those
|
|
2119
|
+
# stay shadowed. Memoized lazily: the Native module can be
|
|
2120
|
+
# defined after this file evaluates.
|
|
2121
|
+
def hot_kind_classes
|
|
2122
|
+
@hot_kind_classes ||=
|
|
2123
|
+
if NATIVE_READ_LAYER &&
|
|
2124
|
+
defined?(::Leptris::XML::Native) &&
|
|
2125
|
+
::Leptris::XML::Native.respond_to?(:define_hot_readers)
|
|
2126
|
+
# Elements: name + content (the C bodies ARE the
|
|
2127
|
+
# contract answers for clean documents). Text: content
|
|
2128
|
+
# only (the text-payload read). Comment/cdata/PI keep
|
|
2129
|
+
# the contract classes outright - their payload reads
|
|
2130
|
+
# are contract-shaped (the reference differential pins
|
|
2131
|
+
# them), so hot classes for those kinds answer wrongly.
|
|
2132
|
+
hot_el = Class.new(Identity::ELEMENT)
|
|
2133
|
+
::Leptris::XML::Native.define_hot_readers(hot_el)
|
|
2134
|
+
hot_el.remove_method(:attribute)
|
|
2135
|
+
hot_tx = Class.new(Identity::TEXT)
|
|
2136
|
+
::Leptris::XML::Native.define_hot_readers(hot_tx)
|
|
2137
|
+
hot_tx.remove_method(:attribute)
|
|
2138
|
+
hot_tx.remove_method(:name)
|
|
2139
|
+
hot_set = [hot_el, hot_tx, Identity::COMMENT,
|
|
2140
|
+
Identity::CDATA,
|
|
2141
|
+
Identity::PROCESSING_INSTRUCTION].freeze
|
|
2142
|
+
# The klass-propagating reads (#246) mint through the
|
|
2143
|
+
# RECEIVER class's child map - the hot classes need their
|
|
2144
|
+
# own, or the C visit mint yields nil for their entries
|
|
2145
|
+
# (the root-level XPath gather truncated at depth >= 2
|
|
2146
|
+
# while the C children read stayed correct).
|
|
2147
|
+
# Install ONLY on the hot classes: the contract kinds'
|
|
2148
|
+
# maps are the load-time installation - overwriting them
|
|
2149
|
+
# here would re-route the contract kinds' children mints.
|
|
2150
|
+
if NATIVE_KLASS_CHILDREN
|
|
2151
|
+
hot_set.first(2).each do |klass|
|
|
2152
|
+
klass.install_child_klasses(hot_set)
|
|
2153
|
+
end
|
|
2154
|
+
end
|
|
2155
|
+
hot_set
|
|
2156
|
+
end
|
|
2157
|
+
end
|
|
2158
|
+
|
|
2159
|
+
def register_mint_klasses!(binding_doc, hot: false)
|
|
2088
2160
|
return binding_doc unless NATIVE_C_MINT && binding_doc
|
|
2089
2161
|
|
|
2090
|
-
|
|
2162
|
+
klass_set = if hot && (klasses = hot_kind_classes)
|
|
2163
|
+
klasses
|
|
2164
|
+
else
|
|
2165
|
+
MINT_KIND_CLASSES
|
|
2166
|
+
end
|
|
2167
|
+
binding_doc.register_wrapper_klasses(klass_set)
|
|
2091
2168
|
binding_doc
|
|
2092
2169
|
end
|
|
2093
2170
|
|
data/lib/moxml/version.rb
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# leptris-ruby#629 — registering SUBCLASSES as wrapper klasses made
|
|
6
|
+
# XPath answer zero rows: wrap_binding_node resolved the node kind
|
|
7
|
+
# through the exact-class hash (IDENTITY_WALK_TYPE), so a subclass
|
|
8
|
+
# minted nil there and every walk-yielded node dropped from results.
|
|
9
|
+
# #340's register_wrapper_klasses admits ANY NativeNode subclass and
|
|
10
|
+
# consumers register their own (define_hot_readers subclasses,
|
|
11
|
+
# leptris-ruby#627) — the resolution must be subclass-aware.
|
|
12
|
+
RSpec.describe "leptris registered-subclass wraps" do
|
|
13
|
+
let(:ctx) { Moxml.new(:leptris) }
|
|
14
|
+
|
|
15
|
+
before do
|
|
16
|
+
unless
|
|
17
|
+
defined?(Leptris::XML::Native.define_hot_readers) &&
|
|
18
|
+
ctx.parse("<r/>").native
|
|
19
|
+
.instance_variable_get(:@doc_klass_map)
|
|
20
|
+
skip "binding lacks the C-mint registered-klass face"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def parse_with_map(map)
|
|
25
|
+
ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
|
|
26
|
+
.tap do |doc|
|
|
27
|
+
doc.native.instance_variable_set(:@doc_klass_map, map) if map
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "matches with the exact classes the adapter registered" do
|
|
32
|
+
doc = parse_with_map(nil) # the adapter registers at parse
|
|
33
|
+
expect(doc.at_xpath("//xmlns:leaf", "xmlns" => "")&.name).to eq("leaf")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "matches with a plain Class.new of the registered element klass" do
|
|
37
|
+
doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
|
|
38
|
+
orig = doc.native.instance_variable_get(:@doc_klass_map)
|
|
39
|
+
map = [Class.new(orig[0]), orig[1], orig[2], orig[3], orig[4]]
|
|
40
|
+
doc.native.instance_variable_set(:@doc_klass_map, map)
|
|
41
|
+
expect(doc.at_xpath("//xmlns:leaf", "xmlns" => "")&.name).to eq("leaf")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "matches with a define_hot_readers subclass registered" do
|
|
45
|
+
doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
|
|
46
|
+
orig = doc.native.instance_variable_get(:@doc_klass_map)
|
|
47
|
+
hot = Class.new(orig[0]) do
|
|
48
|
+
Leptris::XML::Native.define_hot_readers(self)
|
|
49
|
+
end
|
|
50
|
+
doc.native.instance_variable_set(:@doc_klass_map,
|
|
51
|
+
[hot, orig[1], orig[2], orig[3], orig[4]])
|
|
52
|
+
row = doc.at_xpath("//xmlns:leaf", "xmlns" => "")
|
|
53
|
+
expect(row&.name).to eq("leaf")
|
|
54
|
+
expect(row).to be_a(hot) # the consumer's klass mints on walks
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "matches with a subclass of every kind registered" do
|
|
58
|
+
doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
|
|
59
|
+
orig = doc.native.instance_variable_get(:@doc_klass_map)
|
|
60
|
+
map = orig.map { |k| k.is_a?(Class) ? Class.new(k) : k }
|
|
61
|
+
doc.native.instance_variable_set(:@doc_klass_map, map)
|
|
62
|
+
expect(doc.at_xpath("//xmlns:leaf", "xmlns" => "")&.name).to eq("leaf")
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "keeps the mint klass through the walk (contract rides the subclass)" do
|
|
66
|
+
doc = ctx.parse('<root xmlns="urn:a"><child xmlns="urn:b"><leaf xmlns=""/></child></root>')
|
|
67
|
+
orig = doc.native.instance_variable_get(:@doc_klass_map)
|
|
68
|
+
map = orig.map { |k| k.is_a?(Class) ? Class.new(k) : k }
|
|
69
|
+
doc.native.instance_variable_set(:@doc_klass_map, map)
|
|
70
|
+
row = doc.at_xpath("//xmlns:leaf", "xmlns" => "")
|
|
71
|
+
expect(row.class).to eq(map[0])
|
|
72
|
+
expect(row).to be_a(Moxml::Node) # the contract still rides
|
|
73
|
+
end
|
|
74
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: moxml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: |
|
|
14
14
|
Moxml is a unified XML manipulation library that provides a common API
|
|
@@ -498,6 +498,7 @@ files:
|
|
|
498
498
|
- spec/moxml/adapter/leptris_parse_lint_spec.rb
|
|
499
499
|
- spec/moxml/adapter/leptris_parse_skips_spec.rb
|
|
500
500
|
- spec/moxml/adapter/leptris_record_driver_spec.rb
|
|
501
|
+
- spec/moxml/adapter/leptris_registered_subclass_spec.rb
|
|
501
502
|
- spec/moxml/adapter/leptris_sax_dup_attr_spec.rb
|
|
502
503
|
- spec/moxml/adapter/leptris_sax_records_spec.rb
|
|
503
504
|
- spec/moxml/adapter/leptris_spec.rb
|