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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d22f3bb3ecf5566fb8d89432ab482480256b3ccbcec5dbab77baef1bca72a69
4
- data.tar.gz: 7e3fdb8f2faf9116395edbd55a0e2f859271ceee267fef2fda07a262812f16db
3
+ metadata.gz: 463374b3fdb577191db3ac0bafcc5a2fea0d5766328984118008836a05d6cb82
4
+ data.tar.gz: 781b4130bfe0e92d074bf9847847936106534a13a09e43f28c3db705b7700da7
5
5
  SHA512:
6
- metadata.gz: 0e9d2fcd8887331c5528afe7eafbddab1ae230621997ffbcf2e60d8a5f172af7cf00bcddd356ab60f6a9c847b269c3010b4b81b65aba7f567da2b4fc7beb1c2f
7
- data.tar.gz: 8f53b540c0929a434fc131df7255d4462f76dd35d76c42575cf5bcabcbbd875a4c6a49453d9ba3c5e0ff2a3bd5e846e0036b0e73f40f4a23b0632eaed8a6e754
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
- case node
251
- when ::Yeptris::Psych::Nodes::Alias then visit_alias(node)
252
- when ::Yeptris::Psych::Nodes::Scalar then visit_scalar(node)
253
- when ::Yeptris::Psych::Nodes::Sequence then visit_sequence(node)
254
- when ::Yeptris::Psych::Nodes::Mapping then visit_mapping(node)
255
- else node&.to_ruby
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.2".freeze
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
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.2
4
+ version: 0.6.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.