Module: Tenax::Deprecation Private

Defined in:
lib/tenax/deprecation.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Emits deprecation warnings for soft-deprecated API surfaces.

Usage:

Tenax::Deprecation.warn(
"Tenax::Profile#legacy_setting is deprecated",
instead: "Tenax::Profile#new_setting",
removed_in: "1.0"
)

Each unique warning fires once per process by default to avoid log spam. Set TENAX_DEPRECATION_BEHAVIOR to control:

"warn"    (default) - Kernel#warn once per call site
"silence" - suppress warnings entirely
"raise"   - raise on any deprecation use (for testing)

Defined Under Namespace

Classes: DeprecationError

Class Method Summary collapse

Class Method Details

.reset! ⇒ 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.

Reset the seen-warnings cache. Used in tests.



47
48
49
# File 'lib/tenax/deprecation.rb', line 47

def reset!
  @mutex.synchronize { @seen = {} }
end

.warn(message, instead: nil, removed_in: nil) ⇒ 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.

Emit a deprecation warning if not already emitted for this call site.

Parameters:

  • message (String) —

    the deprecation message

  • instead (String, nil) (defaults to: nil) —

    the replacement API

  • removed_in (String, nil) (defaults to: nil) —

    the version where this will be removed



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tenax/deprecation.rb', line 32

def warn(message, instead: nil, removed_in: nil)
  return if behavior == :silence

  full_message = build_message(message, instead, removed_in)
  location = caller_locations(1, 1).first

  case behavior
  when :raise
    raise DeprecationError, full_message
  when :warn
    warn_once(full_message, location)
  end
end