relaton 3.0.0.pre.alpha.8 → 3.0.0.pre.alpha.10

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: 3fafde9870593aca737727dcb4cf8cb142da74d255be4e855eed22bda4bd0f1b
4
- data.tar.gz: 60986309859651e6e1baa05635a1ebfb2fec313f908a5508c14a59ded9ec3f8f
3
+ metadata.gz: 06cb72b9e56ded3fc4232372142ac4d11ab23537c3dedf84bd560236c0f835fd
4
+ data.tar.gz: 92191f7fde44fb7c133c5c079b26e74f0f645b45005d9abae2a7b54fc58f49a9
5
5
  SHA512:
6
- metadata.gz: 2b075475ad0321b604674b8459c60ddc1e7ef10a1a0186e70042348c0d9d5bbe58166cb419548f8d98438040702ffd532204716a261bedaedf20888a5d6c08cf
7
- data.tar.gz: 8b2b003b3b99918b96a42c622607feae3087e2778730a2d31dc94ebe9b51abea23a3f6fbdb254fc72a2daeeae47877feb4edb998d70aa6d0d46c86881db2812c
6
+ metadata.gz: d569654f1591a6e7b28d420166a514acef378fd4aaa4755943bad90ee732362fcd079eb6032a685e58cc5ca5319915388c6db7aefe9a894b787157fae14f1cdf
7
+ data.tar.gz: d3b0e9f6489398563296216cf27c7cb31b761d800fb74fbebd187684b4aded1c16acdfffab3cdc8f83eb71d49722815f7493349789ce067d2f1fb5dea67bb94a
@@ -3,6 +3,7 @@ require "digest"
3
3
  require "json"
4
4
  require "date"
5
5
  require "lutaml/store"
6
+ require "nokogiri"
6
7
  require_relative "cache_entry"
7
8
 
8
9
  module Relaton
@@ -52,6 +53,7 @@ module Relaton
52
53
  archive_old_layout
53
54
  open_stores
54
55
  check_versions
56
+ import_old_layout
55
57
  end
56
58
 
57
59
  # Move the cache to another directory.
@@ -308,6 +310,41 @@ module Relaton
308
310
  Util.info "cache #{dir}: the old cache is moved to #{bak}"
309
311
  end
310
312
 
313
+ # Entries the file-per-key layout cached are imported into the v2
314
+ # stores once, so upgrading does not silently refetch them (relaton#240).
315
+ # A key the v2 cache already holds keeps its fresher entry; not-found
316
+ # and redirection entries are not imported (a negative lookup costs one
317
+ # fetch, and redirects were dropped from the v2 model).
318
+ def import_old_layout
319
+ bak = "#{dir}-v1.bak"
320
+ marker = File.join(dir, LAYOUT, ".v1-imported")
321
+ return if File.exist?(marker) || !Dir.exist?(bak)
322
+
323
+ imported = 0
324
+ Dir.glob("#{bak}/**/*.xml").each do |f|
325
+ value = File.read(f, encoding: "utf-8")
326
+ key = old_layout_key(f.delete_prefix("#{bak}/"), value) or next
327
+ next if lookup(key)
328
+
329
+ self[key] = value
330
+ imported += 1
331
+ end
332
+ FileUtils.touch marker
333
+ Util.info "cache #{dir}: imported #{imported} entries from #{bak}"
334
+ end
335
+
336
+ # The wrapped string key of an old-layout document: its own primary
337
+ # docidentifier under its flavor prefix, resolved through the same
338
+ # `wrapped_key` path a string cache read takes.
339
+ def old_layout_key(path, value)
340
+ flavor = path.split("/").first or return
341
+ doc = Nokogiri::XML(value)
342
+ id = doc.root&.at("./docidentifier[@primary = 'true']") ||
343
+ doc.root&.at("./docidentifier") or return
344
+
345
+ "#{flavor.upcase}(#{id.text.strip})"
346
+ end
347
+
311
348
  # Drop the rows and documents of a flavor whose grammar changed since
312
349
  # they were written.
313
350
  def check_versions
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "3.0.0.pre.alpha.8".freeze
2
+ VERSION = "3.0.0.pre.alpha.10".freeze
3
3
  end
data/lib/relaton.rb CHANGED
@@ -7,16 +7,16 @@
7
7
  require "relaton/version"
8
8
  require "moxml"
9
9
 
10
- # YAML through yeptris (Psych-compatible drop-in; stdlib Psych is kept
11
- # as Yeptris::Psych::ORIGINAL). Must load before any YAML/Psych use.
12
- # yeptris 0.5 moved the exclusive drop-in rebind to yeptris/psych/drop_in
13
- # — plain yeptris/psych only defines the namespace and leaves stdlib
14
- # Psych in place (yeptris-ruby#95, bug 3).
15
- # Load stdlib Psych first: the drop-in keeps it as Yeptris::Psych::ORIGINAL,
16
- # and a later plain require "psych" against the rebound constant is a
17
- # superclass mismatch (yeptris-ruby#95, bug 3 follow-on).
18
- require "psych"
19
- require "yeptris/psych/drop_in"
10
+ # YAML through stdlib Psych. The former yeptris drop-in rebind
11
+ # (require "yeptris/psych/drop_in") replaced ::Psych for the WHOLE
12
+ # host process: every gem that later loaded YAML — glossarist/iev's
13
+ # ISO 639 table, metanorma-cli's collections, anything psych-lenient
14
+ # — silently changed engine, and yeptris 0.6.28.4 diverges from psych
15
+ # (block-scalar headers at column 1, permitted_classes ignored; see
16
+ # yeptris-ruby#258). A library must never rebind global constants;
17
+ # the namespaced Yeptris::Psych API remains the opt-in path for hosts
18
+ # that want it.
19
+ require "yaml"
20
20
 
21
21
  module Relaton
22
22
  autoload :Logger, "relaton/logger"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.alpha.8
4
+ version: 3.0.0.pre.alpha.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-03 00:00:00.000000000 Z
11
+ date: 2026-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable