Module: Invoance::Resources
- Defined in:
- lib/invoance/resources/audit.rb,
lib/invoance/resources/events.rb,
lib/invoance/resources/traces.rb,
lib/invoance/resources/documents.rb,
lib/invoance/resources/attestations.rb
Defined Under Namespace
Classes: Attestations, Audit, Documents, Events, Traces
Class Method Summary collapse
-
.content_idempotency_key(body) ⇒ String
Derive a stable Idempotency-Key from an event body (safe-retry helper).
- .sort_deep_for_stable(v) ⇒ Object private
-
.stable_stringify(value) ⇒ Object
private
Deep-sort all Hash keys (alphabetically) then compact-serialize.
Class Method Details
.content_idempotency_key(body) ⇒ String
Derive a stable Idempotency-Key from an event body (safe-retry helper).
35 36 37 |
# File 'lib/invoance/resources/audit.rb', line 35 def self.content_idempotency_key(body) "idem_" + Digest::SHA256.hexdigest(stable_stringify(body)) end |
.sort_deep_for_stable(v) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/invoance/resources/audit.rb', line 17 def self.sort_deep_for_stable(v) case v when Array v.map { |x| sort_deep_for_stable(x) } when Hash v.keys.map(&:to_s).sort.each_with_object({}) do |k, out| orig = v.key?(k) ? k : k.to_sym out[k] = sort_deep_for_stable(v[orig]) end else v end end |
.stable_stringify(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deep-sort all Hash keys (alphabetically) then compact-serialize. Matches Node's stableStringify: no null-stripping, no schema forcing.
12 13 14 |
# File 'lib/invoance/resources/audit.rb', line 12 def self.stable_stringify(value) JSON.generate(sort_deep_for_stable(value)) end |