yeptris 0.6.1.1 → 0.6.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9b0f5f6a0bcddd8467c3226cbe4438ad2ac119daecbc28395c125045a827825
4
- data.tar.gz: 111a48659d2f3f8f23e3b04ae3dffc1d85fb632a4436887106f89edb583350f4
3
+ metadata.gz: 5d22f3bb3ecf5566fb8d89432ab482480256b3ccbcec5dbab77baef1bca72a69
4
+ data.tar.gz: 7e3fdb8f2faf9116395edbd55a0e2f859271ceee267fef2fda07a262812f16db
5
5
  SHA512:
6
- metadata.gz: dc31a785a9e1bfb683ac4808a9cb58de25d75258d88e7871f8a57d8098e4e84667fb0810b0016eed80c2230260ca6e1a173b1befdbffc2c17d07fdaf07085c2a
7
- data.tar.gz: ea6db1c0c50fe7d6fdd5ebd7bcfdd913e321fc15041deb4f024d03e6558438ff09511591462327279c7e1877b6beb298573c8e5f8067fb36544c08b05d5dc54b
6
+ metadata.gz: 0e9d2fcd8887331c5528afe7eafbddab1ae230621997ffbcf2e60d8a5f172af7cf00bcddd356ab60f6a9c847b269c3010b4b81b65aba7f567da2b4fc7beb1c2f
7
+ data.tar.gz: 8f53b540c0929a434fc131df7255d4462f76dd35d76c42575cf5bcabcbbd875a4c6a49453d9ba3c5e0ff2a3bd5e846e0036b0e73f40f4a23b0632eaed8a6e754
@@ -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
- m.set_tag("!ruby/object:#{obj.class.name}")
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
@@ -331,7 +334,13 @@ module Yeptris
331
334
  klass = resolve_class(Regexp.last_match(1).to_s)
332
335
  revive_object(klass, node)
333
336
  else
334
- hash_into({}, node)
337
+ # Psych.load_tags first (the class registry, #95 bug 4);
338
+ # anything else stays the plain mapping
339
+ if (klass = ::Yeptris::Psych.load_tags[tag])
340
+ revive_tagged(klass, node)
341
+ else
342
+ hash_into({}, node)
343
+ end
335
344
  end
336
345
  end
337
346
 
@@ -343,6 +352,23 @@ module Yeptris
343
352
  h
344
353
  end
345
354
 
355
+ # A load_tags-registered class revives from the mapping's own
356
+ # top-level pairs (Psych's coder semantics — no __init__
357
+ # wrapper, which is OUR encoder's internal convention)
358
+ def revive_tagged(klass, node)
359
+ raise ::Yeptris::DumpError,
360
+ "#{klass} is not Yeptris::Psych::Encodable: implement init_with(coder)" unless klass <= ::Yeptris::Psych::Encodable
361
+
362
+ obj = klass.allocate
363
+ anchors[node.anchor] = obj if node.anchor
364
+ coder = ::Yeptris::Psych::CoderShim.new
365
+ node.children.each_slice(2) do |k, v|
366
+ coder[k.to_ruby.to_s] = visit(v)
367
+ end
368
+ obj.init_with(coder)
369
+ obj
370
+ end
371
+
346
372
  def revive_object(klass, node)
347
373
  # bare !ruby/object (no class): Psych.dump(Object.new)'s form.
348
374
  # An Object has no declared state — allocation is the whole
data/lib/yeptris/psych.rb CHANGED
@@ -17,6 +17,28 @@ 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
+ end
41
+
20
42
  # Children load via autoload declared HERE — the immediate parent
21
43
  # namespace's file (never internal requires).
22
44
  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 Date, Time then scalar(obj.iso8601, STYLE_PLAIN, emit, blob, off)
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 Date, Time then new_scalar(doc, obj.iso8601)
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.1".freeze
6
+ VERSION = "0.6.1.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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yeptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1.1
4
+ version: 0.6.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.