Module: Hyperion::Deprecations
- Defined in:
- lib/hyperion/deprecations.rb
Overview
1.8.0 deprecation-warn helper. RFC §3 requires a one-shot warn per deprecated API call site / key per process — emitted via the runtime logger when available, falling back to $stderr at very-early boot (before ‘Hyperion::Runtime.default.logger` is reachable).
The deprecated APIs themselves keep working untouched in 1.8.0; the warn is purely informational. Removal lands in 2.0.0 per the RFC §3 release plan.
Tests that trip the deprecation paths intentionally can capture the output by swapping ‘Hyperion::Runtime.default.logger`; tests that want silence call `Deprecations.silence!` in a `before(:each)` and `Deprecations.reset!` in `after(:each)` to start with a clean slate.
Constant Summary collapse
- MUTEX =
Mutex.new
Class Method Summary collapse
-
.reset! ⇒ Object
Test seam: clear the dedup table so a spec can re-trigger a warn it just exercised.
-
.silence! ⇒ Object
Test seam: suppress all warns until ‘unsilence!` is called.
- .silenced? ⇒ Boolean
- .unsilence! ⇒ Object
-
.warn_once(key, message) ⇒ Object
Emit a one-shot deprecation warn for ‘key`.
-
.warned?(key) ⇒ Boolean
Visibility for assertion: did we already warn on ‘key`?.
Class Method Details
.reset! ⇒ Object
Test seam: clear the dedup table so a spec can re-trigger a warn it just exercised. Combined with ‘silence!`/`unsilence!` tests can both assert the dedup behaviour and avoid noise on baseline runs.
43 44 45 |
# File 'lib/hyperion/deprecations.rb', line 43 def reset! MUTEX.synchronize { @warned.clear } end |
.silence! ⇒ Object
Test seam: suppress all warns until ‘unsilence!` is called. Used by the broad test suite which intentionally exercises the deprecated DSL surface and would otherwise flood output.
50 51 52 |
# File 'lib/hyperion/deprecations.rb', line 50 def silence! @silenced = true end |
.silenced? ⇒ Boolean
58 59 60 |
# File 'lib/hyperion/deprecations.rb', line 58 def silenced? @silenced end |
.unsilence! ⇒ Object
54 55 56 |
# File 'lib/hyperion/deprecations.rb', line 54 def unsilence! @silenced = false end |
.warn_once(key, message) ⇒ Object
Emit a one-shot deprecation warn for ‘key`. Subsequent calls with the same key in the same process are no-ops. Thread-safe (the check-and-record runs under a Mutex) so two workers initializing at once don’t double-emit on the same key.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/hyperion/deprecations.rb', line 28 def warn_once(key, ) return if @silenced MUTEX.synchronize do return if @warned[key] @warned[key] = true end emit("[hyperion] DEPRECATION: #{}") end |
.warned?(key) ⇒ Boolean
Visibility for assertion: did we already warn on ‘key`?
63 64 65 |
# File 'lib/hyperion/deprecations.rb', line 63 def warned?(key) MUTEX.synchronize { @warned.key?(key) } end |