yeptris 0.6.1.3 → 0.6.2.2
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/ffi.rb +3 -0
- data/lib/yeptris/node.rb +11 -0
- data/lib/yeptris/psych/visitors.rb +25 -5
- data/lib/yeptris/psych.rb +23 -1
- data/lib/yeptris/yaml.rb +19 -3
- 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: c7cbac43219b4ebaa9e50dd2e31f952e04e147f61a2b31da36607ecdd6ec6353
|
|
4
|
+
data.tar.gz: 1776b7da27e9e9a3686eadd95cc36d18b961ccb536a070a50ddb4f78e22e972a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 320f371c5a058d59954f78b71f1735fc4d0c085034a6685fc7b9f903694dc1528a6fb754fd98fa93ff5ae848fa9d91ad3c6272e115dc9d3c1390fe3efc517221
|
|
7
|
+
data.tar.gz: cdae458f8fa79763c28c30ec3c2d1479c57180147af0b5171fe20ff415fd2f723218ba984c016185781983de2c1a5e39421039a2127855c6a7ab54d8dd4e3f27
|
data/lib/yeptris/ffi.rb
CHANGED
|
@@ -89,6 +89,8 @@ module Yeptris
|
|
|
89
89
|
%i[yeptris_document pointer size_t int], :yeptris_node
|
|
90
90
|
attach_function :yeptris_node_map_add,
|
|
91
91
|
%i[yeptris_node pointer size_t yeptris_node], :int
|
|
92
|
+
attach_function :yeptris_node_map_add_node,
|
|
93
|
+
%i[yeptris_node yeptris_node yeptris_node], :int
|
|
92
94
|
attach_function :yeptris_node_map_set,
|
|
93
95
|
%i[yeptris_node pointer size_t yeptris_node], :int
|
|
94
96
|
attach_function :yeptris_node_map_del, %i[yeptris_node pointer size_t], :int
|
|
@@ -176,6 +178,7 @@ module Yeptris
|
|
|
176
178
|
BUILD_SEQ = 2
|
|
177
179
|
BUILD_MAP = 3
|
|
178
180
|
BUILD_END = 4
|
|
181
|
+
BUILD_TAG = 5
|
|
179
182
|
|
|
180
183
|
# the ABI-pinned shape; the bulk builder packs these bytes
|
|
181
184
|
# directly (12 per entry)
|
data/lib/yeptris/node.rb
CHANGED
|
@@ -201,6 +201,17 @@ class Yeptris::Node
|
|
|
201
201
|
self
|
|
202
202
|
end
|
|
203
203
|
|
|
204
|
+
# A pre-built key NODE ( Psych parity: nil keys ride the explicit
|
|
205
|
+
# `!` tag on an empty single-quoted scalar, which the byte-key form
|
|
206
|
+
# cannot carry)
|
|
207
|
+
def map_add_node(key_node, node)
|
|
208
|
+
rc = alive do
|
|
209
|
+
Yeptris::FFI.yeptris_node_map_add_node(@c_ptr, key_node.c_ptr, node.c_ptr)
|
|
210
|
+
end
|
|
211
|
+
Yeptris::FFI.check_status(rc, "yeptris_node_map_add_node")
|
|
212
|
+
self
|
|
213
|
+
end
|
|
214
|
+
|
|
204
215
|
def map_set(key, node)
|
|
205
216
|
key = key.to_s
|
|
206
217
|
rc = alive { Yeptris::FFI.yeptris_node_map_set(@c_ptr, key, key.bytesize, node.c_ptr) }
|
|
@@ -12,6 +12,12 @@ module Yeptris
|
|
|
12
12
|
# objects, aliases for repeats, the Encodable protocol, and the
|
|
13
13
|
# !ruby/... tags Psych's own emitter produces.
|
|
14
14
|
class YAMLTree
|
|
15
|
+
# stdlib's factory (relaton's db cache calls it): the options
|
|
16
|
+
# ride our visitor defaults
|
|
17
|
+
def self.create(options = {}, emitter = nil)
|
|
18
|
+
new
|
|
19
|
+
end
|
|
20
|
+
|
|
15
21
|
def initialize
|
|
16
22
|
@tree = ::Yeptris::Document.create
|
|
17
23
|
@names = {} # object_id -> anchor name
|
|
@@ -114,14 +120,18 @@ module Yeptris
|
|
|
114
120
|
# strings route through the builder's plain-safety helper
|
|
115
121
|
# (one quoting rule, DRY); other scalars are their own text
|
|
116
122
|
text =
|
|
117
|
-
if obj.is_a?(::
|
|
118
|
-
|
|
123
|
+
if obj.is_a?(::Time)
|
|
124
|
+
# psych-5's format_time (#300 family 1) — the FIRST cut
|
|
125
|
+
# put this branch after the Date||Time iso8601 one, dead
|
|
126
|
+
# code: Psych.dump of a Hash still emitted iso8601 (the
|
|
127
|
+
# neutral surface alone was pinned)
|
|
128
|
+
::Yeptris::YAML::BulkBuilder.time_text(obj)
|
|
129
|
+
elsif obj.is_a?(::Date)
|
|
130
|
+
obj.iso8601 # canonical calendar form (DateTime rides here too)
|
|
119
131
|
elsif obj.nil?
|
|
120
132
|
"" # libyaml's null rendering rides bare (issue #290)
|
|
121
133
|
elsif obj.is_a?(::Float)
|
|
122
134
|
::Yeptris::YAML::BulkBuilder.float_text(obj)
|
|
123
|
-
elsif obj.is_a?(::Time)
|
|
124
|
-
::Yeptris::YAML::BulkBuilder.time_text(obj)
|
|
125
135
|
else
|
|
126
136
|
obj.to_s
|
|
127
137
|
end
|
|
@@ -142,7 +152,17 @@ module Yeptris
|
|
|
142
152
|
m = @tree.new_mapping
|
|
143
153
|
remember(hash, m)
|
|
144
154
|
m.set_anchor(name) if name
|
|
145
|
-
hash.each
|
|
155
|
+
hash.each do |k, v|
|
|
156
|
+
if k.nil?
|
|
157
|
+
# Psych's nil-key form: `! ''` — the explicit tag on an
|
|
158
|
+
# empty single-quoted key (#300 family 2)
|
|
159
|
+
key_node = @tree.new_scalar("", :single_quoted)
|
|
160
|
+
key_node.set_tag("!")
|
|
161
|
+
m.map_add_node(key_node, visit(v))
|
|
162
|
+
else
|
|
163
|
+
m.map_add(key_text(k), visit(v))
|
|
164
|
+
end
|
|
165
|
+
end
|
|
146
166
|
m
|
|
147
167
|
end
|
|
148
168
|
|
data/lib/yeptris/psych.rb
CHANGED
|
@@ -184,7 +184,15 @@ module Yeptris
|
|
|
184
184
|
|
|
185
185
|
# Arbitrary object graphs through the YAMLTree visitor
|
|
186
186
|
# (anchors, !ruby/ tags); plain data rides the fast builder.
|
|
187
|
-
def dump(obj, io = nil)
|
|
187
|
+
def dump(obj, io = nil, options = {})
|
|
188
|
+
# stdlib's Object#to_yaml calls Psych.dump(self, options) —
|
|
189
|
+
# the options hash lands in the io slot positionally; treat a
|
|
190
|
+
# Hash there as options (the options themselves ride the
|
|
191
|
+
# visitor's defaults, #95 thread)
|
|
192
|
+
if io.is_a?(::Hash)
|
|
193
|
+
options = io
|
|
194
|
+
io = nil
|
|
195
|
+
end
|
|
188
196
|
# scalars take the fast builder; EVERYTHING else (including
|
|
189
197
|
# plain containers — they may nest custom objects) goes
|
|
190
198
|
# through the visitor, which builds the same DOM for plain
|
|
@@ -420,6 +428,20 @@ end
|
|
|
420
428
|
# yeptris/psych/drop_in — process-exclusive by nature, since the
|
|
421
429
|
# stdlib cannot be prevented from re-opening whatever ::Psych points
|
|
422
430
|
# at once IT loads.
|
|
431
|
+
# The core extension (stdlib psych/core_ext parity): Object#to_yaml
|
|
432
|
+
# and Object.yaml_tag exist whether the consumer came through stdlib
|
|
433
|
+
# psych first or pure drop-in. Both definitions are compatible —
|
|
434
|
+
# whoever loads last wins, and both call the rebound Psych.dump.
|
|
435
|
+
class Object
|
|
436
|
+
def self.yaml_tag(url)
|
|
437
|
+
::Yeptris::Psych.add_tag(url, self)
|
|
438
|
+
end
|
|
439
|
+
|
|
440
|
+
def to_yaml(options = {})
|
|
441
|
+
::Yeptris::Psych.dump(self, options)
|
|
442
|
+
end
|
|
443
|
+
end
|
|
444
|
+
|
|
423
445
|
# 0.4-contract migration signal (issue #95): this require used to
|
|
424
446
|
# rebind ::Psych. It does not anymore, and re-binding it here would
|
|
425
447
|
# regress #69 (any stdlib psych loaded afterwards would explode with
|
data/lib/yeptris/yaml.rb
CHANGED
|
@@ -102,6 +102,7 @@ module Yeptris
|
|
|
102
102
|
STYLE_SQ = 2
|
|
103
103
|
STYLE_DQ = 3
|
|
104
104
|
STYLE_LIT = 4
|
|
105
|
+
BUILD_TAG = Yeptris::FFI::BUILD_TAG
|
|
105
106
|
|
|
106
107
|
module_function
|
|
107
108
|
|
|
@@ -164,8 +165,15 @@ module Yeptris
|
|
|
164
165
|
# reader resolves them back to Symbols; Integer/Float/
|
|
165
166
|
# bool keys ride plain like their values (Psych emits
|
|
166
167
|
# 1: unquoted — #290 family 5); string keys ride the
|
|
167
|
-
# visit_String rules like any other scalar
|
|
168
|
-
|
|
168
|
+
# visit_String rules like any other scalar; NIL keys
|
|
169
|
+
# ride Psych's explicit-`!` empty-scalar form
|
|
170
|
+
# (#300 family 2)
|
|
171
|
+
if k.nil?
|
|
172
|
+
scalar("", STYLE_SQ, emit, blob, off)
|
|
173
|
+
emit.call(BUILD_TAG, 0, off[0], 1)
|
|
174
|
+
blob << "!"
|
|
175
|
+
off[0] += 1
|
|
176
|
+
elsif k.is_a?(Symbol)
|
|
169
177
|
scalar(":#{k}", STYLE_PLAIN, emit, blob, off)
|
|
170
178
|
elsif k.is_a?(String)
|
|
171
179
|
place(k, emit, blob, off, seen)
|
|
@@ -316,7 +324,15 @@ module Yeptris
|
|
|
316
324
|
def build_map(doc, h, seen)
|
|
317
325
|
cycle_guard(h, seen) do
|
|
318
326
|
m = doc.new_mapping
|
|
319
|
-
h.each
|
|
327
|
+
h.each do |k, v|
|
|
328
|
+
if k.nil?
|
|
329
|
+
key_node = doc.new_scalar("", :single_quoted)
|
|
330
|
+
key_node.set_tag("!")
|
|
331
|
+
m.map_add_node(key_node, build(doc, v, seen))
|
|
332
|
+
else
|
|
333
|
+
m.map_add(key_text(k), build(doc, v, seen))
|
|
334
|
+
end
|
|
335
|
+
end
|
|
320
336
|
m
|
|
321
337
|
end
|
|
322
338
|
end
|
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.
|
|
6
|
+
VERSION = "0.6.2.2".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
|