yeptris 0.6.1.1-aarch64-linux → 0.6.1.3-aarch64-linux
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 +56 -8
- data/lib/yeptris/psych.rb +54 -0
- data/lib/yeptris/yaml.rb +10 -2
- 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: 3e5b8193f2815d4e3d52870b429abcb0e8253aa8f0d9309f31927e72f77d4a5d
|
|
4
|
+
data.tar.gz: f6e011eb746bc702ab53044c288dcfc28642b55d523394a957ff6e90e01cdb20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 06eb30461b0a3a5bbf2024425c47e6fd9d313d073a62fe73d69dfa08cd97e5934e0f528bbd02df7ee0eba6af6359715ec67b9e378d8a4ad31f9b9342f613e3f0
|
|
7
|
+
data.tar.gz: 625b12f9093edf683420ba81788c81e4e52a73ec5805184264c00aaafbee52461c16baba982871290e0f3d128c3e8f7cd1daeb67a3e6ac406cf791e65f6dbb4a
|
|
@@ -120,6 +120,8 @@ module Yeptris
|
|
|
120
120
|
"" # libyaml's null rendering rides bare (issue #290)
|
|
121
121
|
elsif obj.is_a?(::Float)
|
|
122
122
|
::Yeptris::YAML::BulkBuilder.float_text(obj)
|
|
123
|
+
elsif obj.is_a?(::Time)
|
|
124
|
+
::Yeptris::YAML::BulkBuilder.time_text(obj)
|
|
123
125
|
else
|
|
124
126
|
obj.to_s
|
|
125
127
|
end
|
|
@@ -204,7 +206,8 @@ module Yeptris
|
|
|
204
206
|
end
|
|
205
207
|
m = @tree.new_mapping
|
|
206
208
|
m.set_anchor(name) if name
|
|
207
|
-
|
|
209
|
+
custom = ::Yeptris::Psych.dump_tags[obj.class]
|
|
210
|
+
m.set_tag(custom || "!ruby/object:#{obj.class.name}")
|
|
208
211
|
m.map_add("__init__", init)
|
|
209
212
|
remember(obj, m)
|
|
210
213
|
m
|
|
@@ -242,15 +245,37 @@ module Yeptris
|
|
|
242
245
|
new.visit(node)
|
|
243
246
|
end
|
|
244
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
|
+
|
|
245
263
|
def visit(node)
|
|
246
264
|
@root ||= node
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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)
|
|
253
277
|
end
|
|
278
|
+
result
|
|
254
279
|
end
|
|
255
280
|
|
|
256
281
|
private
|
|
@@ -331,7 +356,13 @@ module Yeptris
|
|
|
331
356
|
klass = resolve_class(Regexp.last_match(1).to_s)
|
|
332
357
|
revive_object(klass, node)
|
|
333
358
|
else
|
|
334
|
-
|
|
359
|
+
# Psych.load_tags first (the class registry, #95 bug 4);
|
|
360
|
+
# anything else stays the plain mapping
|
|
361
|
+
if (klass = ::Yeptris::Psych.load_tags[tag])
|
|
362
|
+
revive_tagged(klass, node)
|
|
363
|
+
else
|
|
364
|
+
hash_into({}, node)
|
|
365
|
+
end
|
|
335
366
|
end
|
|
336
367
|
end
|
|
337
368
|
|
|
@@ -343,6 +374,23 @@ module Yeptris
|
|
|
343
374
|
h
|
|
344
375
|
end
|
|
345
376
|
|
|
377
|
+
# A load_tags-registered class revives from the mapping's own
|
|
378
|
+
# top-level pairs (Psych's coder semantics — no __init__
|
|
379
|
+
# wrapper, which is OUR encoder's internal convention)
|
|
380
|
+
def revive_tagged(klass, node)
|
|
381
|
+
raise ::Yeptris::DumpError,
|
|
382
|
+
"#{klass} is not Yeptris::Psych::Encodable: implement init_with(coder)" unless klass <= ::Yeptris::Psych::Encodable
|
|
383
|
+
|
|
384
|
+
obj = klass.allocate
|
|
385
|
+
anchors[node.anchor] = obj if node.anchor
|
|
386
|
+
coder = ::Yeptris::Psych::CoderShim.new
|
|
387
|
+
node.children.each_slice(2) do |k, v|
|
|
388
|
+
coder[k.to_ruby.to_s] = visit(v)
|
|
389
|
+
end
|
|
390
|
+
obj.init_with(coder)
|
|
391
|
+
obj
|
|
392
|
+
end
|
|
393
|
+
|
|
346
394
|
def revive_object(klass, node)
|
|
347
395
|
# bare !ruby/object (no class): Psych.dump(Object.new)'s form.
|
|
348
396
|
# An Object has no declared state — allocation is the whole
|
data/lib/yeptris/psych.rb
CHANGED
|
@@ -17,6 +17,60 @@ require "set"
|
|
|
17
17
|
# document without materializing.
|
|
18
18
|
module Yeptris
|
|
19
19
|
module Psych
|
|
20
|
+
# The tag registries (Psych's class-level API, #95 bug 4):
|
|
21
|
+
# load_tags maps a serialized tag to the Class that revives it;
|
|
22
|
+
# dump_tags overrides the emitted tag for a Class. Consulted by
|
|
23
|
+
# the revival visitor (custom tags) and the dumper's tag choice.
|
|
24
|
+
class << self
|
|
25
|
+
def load_tags
|
|
26
|
+
@load_tags ||= {}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def load_tags=(tags)
|
|
30
|
+
@load_tags = tags
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dump_tags
|
|
34
|
+
@dump_tags ||= {}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def dump_tags=(tags)
|
|
38
|
+
@dump_tags = tags
|
|
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
|
|
72
|
+
end
|
|
73
|
+
|
|
20
74
|
# Children load via autoload declared HERE — the immediate parent
|
|
21
75
|
# namespace's file (never internal requires).
|
|
22
76
|
autoload :Handler, "yeptris/psych/handler"
|
data/lib/yeptris/yaml.rb
CHANGED
|
@@ -105,6 +105,12 @@ module Yeptris
|
|
|
105
105
|
|
|
106
106
|
module_function
|
|
107
107
|
|
|
108
|
+
# Psych's exact timestamp spelling (format_time, #300): space
|
|
109
|
+
# separated, nanosecond width, Z for UTC — iso8601 diverged
|
|
110
|
+
def time_text(t)
|
|
111
|
+
t.utc? ? t.strftime("%Y-%m-%d %H:%M:%S.%9N Z") : t.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")
|
|
112
|
+
end
|
|
113
|
+
|
|
108
114
|
# Psych's float spelling (#290): Infinity/NAN ride the YAML words,
|
|
109
115
|
# not Ruby's to_s (which prints "Infinity"/"NaN" — a STRING on
|
|
110
116
|
# reload)
|
|
@@ -182,7 +188,8 @@ module Yeptris
|
|
|
182
188
|
when Float then scalar(float_text(obj), STYLE_PLAIN, emit, blob, off)
|
|
183
189
|
when true, false then scalar(obj.to_s, STYLE_PLAIN, emit, blob, off)
|
|
184
190
|
when nil then scalar("", STYLE_PLAIN, emit, blob, off)
|
|
185
|
-
when
|
|
191
|
+
when Time then scalar(time_text(obj), STYLE_PLAIN, emit, blob, off)
|
|
192
|
+
when Date then scalar(obj.iso8601, STYLE_PLAIN, emit, blob, off)
|
|
186
193
|
else
|
|
187
194
|
raise DumpError,
|
|
188
195
|
"cannot dump #{obj.class}: unsupported object " \
|
|
@@ -297,7 +304,8 @@ module Yeptris
|
|
|
297
304
|
when Float then new_scalar(doc, BulkBuilder.float_text(obj))
|
|
298
305
|
when true, false then new_scalar(doc, obj.to_s)
|
|
299
306
|
when nil then new_scalar(doc, "")
|
|
300
|
-
when
|
|
307
|
+
when Time then new_scalar(doc, BulkBuilder.time_text(obj))
|
|
308
|
+
when Date then new_scalar(doc, obj.iso8601)
|
|
301
309
|
else
|
|
302
310
|
raise DumpError,
|
|
303
311
|
"cannot dump #{obj.class}: unsupported object " \
|
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
|