yeptris 0.6.1.2 → 0.6.1.3
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/yeptris/psych/visitors.rb +28 -6
- data/lib/yeptris/psych.rb +32 -0
- data/lib/yeptris.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 463374b3fdb577191db3ac0bafcc5a2fea0d5766328984118008836a05d6cb82
|
|
4
|
+
data.tar.gz: 781b4130bfe0e92d074bf9847847936106534a13a09e43f28c3db705b7700da7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 976b27c17df3ead867fdcf14935b745a6a37846718a277b3077895d6132a91c03ad062d52e3556805ff6496e0101d8311770318f6c0d207afdb1c40201a9f26e
|
|
7
|
+
data.tar.gz: '0195f2564404cd3b73712806af34794bbbf682f91ee026c0715d40b2d19a5165a496f5c058865900ca5ca8dbcb4c06f9bee7255cb636bde2d51633cf332b3494'
|
|
@@ -245,15 +245,37 @@ module Yeptris
|
|
|
245
245
|
new.visit(node)
|
|
246
246
|
end
|
|
247
247
|
|
|
248
|
+
# stdlib ToRuby#accept's domain post-pass: normalize the tag
|
|
249
|
+
# (strip leading !//, ensure tag: unless x-private) and run the
|
|
250
|
+
# registered block over the revived result (#95 thread)
|
|
251
|
+
def apply_domain_type(result, node)
|
|
252
|
+
return result if node.tag.nil? || node.tag.empty?
|
|
253
|
+
|
|
254
|
+
key = node.tag.sub(/\A[!\/]*/, "").sub(/(,\d+)\//, '\1:')
|
|
255
|
+
key = "tag:#{key}" unless key.match?(/\A(?:tag:|x-private)/)
|
|
256
|
+
entry = ::Yeptris::Psych.domain_types[key]
|
|
257
|
+
return result unless entry
|
|
258
|
+
|
|
259
|
+
_value, block = entry
|
|
260
|
+
block.call(key, result)
|
|
261
|
+
end
|
|
262
|
+
|
|
248
263
|
def visit(node)
|
|
249
264
|
@root ||= node
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
265
|
+
result =
|
|
266
|
+
case node
|
|
267
|
+
when ::Yeptris::Psych::Nodes::Alias then visit_alias(node)
|
|
268
|
+
when ::Yeptris::Psych::Nodes::Scalar then visit_scalar(node)
|
|
269
|
+
when ::Yeptris::Psych::Nodes::Sequence then visit_sequence(node)
|
|
270
|
+
when ::Yeptris::Psych::Nodes::Mapping then visit_mapping(node)
|
|
271
|
+
else node&.to_ruby
|
|
272
|
+
end
|
|
273
|
+
# the domain-types post-pass (stdlib ToRuby#accept's tail):
|
|
274
|
+
# registered blocks transform the revived result per node
|
|
275
|
+
if node && !::Yeptris::Psych.domain_types.empty?
|
|
276
|
+
result = apply_domain_type(result, node)
|
|
256
277
|
end
|
|
278
|
+
result
|
|
257
279
|
end
|
|
258
280
|
|
|
259
281
|
private
|
data/lib/yeptris/psych.rb
CHANGED
|
@@ -37,6 +37,38 @@ module Yeptris
|
|
|
37
37
|
def dump_tags=(tags)
|
|
38
38
|
@dump_tags = tags
|
|
39
39
|
end
|
|
40
|
+
|
|
41
|
+
# The third registry (stdlib psych carries all three; the rebind
|
|
42
|
+
# broke relaton/lutaml callers that wrote it — the 26x
|
|
43
|
+
# undefined-method report). Keys are normalized tag strings
|
|
44
|
+
# ("tag:DOMAIN:TYPE"), values are [key, block] post-processors.
|
|
45
|
+
def domain_types
|
|
46
|
+
@domain_types ||= {}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def domain_types=(types)
|
|
50
|
+
@domain_types = types
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def add_domain_type(domain, type_tag, &block)
|
|
54
|
+
key = ["tag", domain, type_tag].join(":")
|
|
55
|
+
domain_types[key] = [key, block]
|
|
56
|
+
domain_types["tag:#{type_tag}"] = [key, block]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def add_builtin_type(type_tag, &block)
|
|
60
|
+
key = ["tag", "yaml.org,2002", type_tag].join(":")
|
|
61
|
+
domain_types[key] = [key, block]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def remove_type(type_tag)
|
|
65
|
+
domain_types.delete type_tag
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def add_tag(tag, klass)
|
|
69
|
+
load_tags[tag] = klass.name
|
|
70
|
+
dump_tags[klass] = tag
|
|
71
|
+
end
|
|
40
72
|
end
|
|
41
73
|
|
|
42
74
|
# Children load via autoload declared HERE — the immediate parent
|
data/lib/yeptris.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Yeptris
|
|
4
4
|
# The gem's version lives in the parent namespace's file — the last
|
|
5
5
|
# internal require (yeptris/version) retired with it.
|
|
6
|
-
VERSION = "0.6.1.
|
|
6
|
+
VERSION = "0.6.1.3".freeze
|
|
7
7
|
# The error hierarchy lives in THIS file (the parent namespace's
|
|
8
8
|
# own file): nested constants do not trigger a parent-constant
|
|
9
9
|
# autoload, and the law forbids internal requires — defining the
|