metanorma-utils 2.0.11 → 2.0.12

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: 4bf5d712d55cb73ba43cc6bfc97814fc8dd56989afc9ab8abbacf38d58f620e1
4
- data.tar.gz: 210beeb0bf946b01fbcfbd3db0bb6845322e6c58e4fb134471bf9e714eb6b2ea
3
+ metadata.gz: 0c1e1dcd39f422719231a463baad92a7cfb2774836497b5b862c9baa1bf457f1
4
+ data.tar.gz: a665005b573ead115c5304f1ddaa675070dd73b5563e120046610133fa3f2690
5
5
  SHA512:
6
- metadata.gz: bc01cd86992bfe05030beca1094025f04cd64110fa3b896c718a3a8f0ca16ac1883128ad6e97747011c53d075849ff6c4b8b5c7996d35cf081321e5bf19eaa8d
7
- data.tar.gz: 28950533206989b2bdb78b5d88b79df3cc9a491f8a1d01f96f91841ce230f83bf9e435795dff082e96d7d6d3d2139f96e43e77c57ea3adccf7c0d1e0e2de7bf6
6
+ metadata.gz: 35ab1ff450498d18369cb240313c830347a8d90dee2c6a690341901ddc6bf00f64fe2797501df48777d0858b5ee409ee91d1a98842048bcd56de07807749625c
7
+ data.tar.gz: 15e6daaa1c5c2a8db6ae670d0f045465f65fa001e24632592515b31ca71cd4149eb1f03082272df45104b333f64bff7172518ae8ed4781ef0e6bf9d91faffedc
data/lib/utils/log.rb CHANGED
@@ -4,12 +4,23 @@ require_relative "log_html"
4
4
  module Metanorma
5
5
  module Utils
6
6
  class Log
7
- attr_accessor :suppress_log
7
+ attr_accessor :suppress_log, :suppression
8
8
 
9
9
  # messages: hash of message IDs to {error, severity, category}
10
10
  # severity: 0: abort; 1: serious; 2: not serious; 3: info only
11
+ #
12
+ # suppression: optional object answering
13
+ # action_for(id:, message:, category:, severity:, location:)
14
+ # returning nil or { action: :off | :reclassify | :exclude | :allow,
15
+ # reason: String, severity: Integer } (severity for :reclassify).
16
+ # :off, :exclude and :allow route to the suppressed store (audited,
17
+ # never silently dropped); :reclassify overrides the entry's
18
+ # severity before any severity-based decision. Declarative
19
+ # validation suppression, metanorma-standoc#1369.
11
20
  def initialize(messages = {})
12
21
  @log = {}
22
+ @suppressed_messages = []
23
+ @suppression = nil
13
24
  @c = HTMLEntities.new
14
25
  @mapid = {}
15
26
  @suppress_log = { severity: 4, category: [], error_ids: [],
@@ -51,12 +62,49 @@ module Metanorma
51
62
  msg = create_entry(loc, m[:error], m[:severity], id, params)
52
63
  return if suppressed_message?(msg[:error])
53
64
 
65
+ # ::Hash: Metanorma::Utils::Hash shadows the core constant here
66
+ case (action = suppression_action(msg, m, id, loc))
67
+ when ::Hash
68
+ case action[:action]
69
+ when :off, :exclude, :allow
70
+ record_suppressed(msg, action)
71
+ return
72
+ when :reclassify
73
+ # Reclassification precedes every severity-based decision, so a
74
+ # severity-0 (abort) entry reclassified away never aborts, and
75
+ # the active log carries the configured severity.
76
+ msg[:severity] = action[:severity]
77
+ end
78
+ end
79
+
54
80
  @log[m[:category]] << msg
55
81
  loc = loc.nil? ? "" : "(#{current_location(loc)[0]}): "
56
82
  suppress_display?(m[:category], loc, msg, display) or
57
83
  warn "#{m[:category]}: #{loc}#{msg[:error]}"
58
84
  end
59
85
 
86
+ # Entries suppressed by the suppression hook: normal message shape,
87
+ # plus the suppression reason and the severity before suppression.
88
+ # The store is per-instance, like @log.
89
+ attr_reader :suppressed_messages
90
+
91
+ def suppressed?
92
+ !@suppressed_messages.empty?
93
+ end
94
+
95
+ # internal, but left public: this class has no private surface and
96
+ # flavors re-open it
97
+ def suppression_action(msg, m, id, loc)
98
+ @suppression&.action_for(id: id.to_s, message: msg[:error],
99
+ category: m[:category],
100
+ severity: msg[:severity], location: loc)
101
+ end
102
+
103
+ def record_suppressed(msg, action)
104
+ @suppressed_messages << msg.merge(suppressed_by: action[:reason],
105
+ original_severity: msg[:severity])
106
+ end
107
+
60
108
  def abort_messages
61
109
  @log.values.each_with_object([]) do |v, m|
62
110
  v.each do |e|
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "2.0.11".freeze
3
+ VERSION = "2.0.12".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.11
4
+ version: 2.0.12
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-11-05 00:00:00.000000000 Z
11
+ date: 2026-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor