Module: AdminSuite::Deprecation

Included in:
Admin::Base::Resource, LegacyCustomRendererProcs, Renderers::LegacyGleania
Defined in:
lib/admin_suite/deprecation.rb

Overview

Per-process, once-per-key deprecation warning support.

Originally lived only on AdminSuite::Renderers::LegacyGleania (the four legacy Gleania renderers); pulled out here so Admin::Base::Resource (the exportable no-op) and the legacy config.custom_renderers proc path can share the same once-per-key behavior instead of re-implementing it, without becoming a general-purpose deprecation framework.

extend this module to get an independent @warned_keys store scoped to the extending object (a module, or -- via singleton-method inheritance -- each subclass of a class that extends it).

Instance Method Summary collapse

Instance Method Details

#reset_deprecation_notices!void

This method returns an undefined value.



30
31
32
# File 'lib/admin_suite/deprecation.rb', line 30

def reset_deprecation_notices!
  @warned_keys = {}
end

#warn_once(key, message) ⇒ void

This method returns an undefined value.

Fires the deprecation sink at most once per key per process (per extending object).

Parameters:

  • key (Object)

    anything hashable identifying the deprecated thing

  • message (String)

    fully-formatted deprecation message



40
41
42
43
44
45
46
# File 'lib/admin_suite/deprecation.rb', line 40

def warn_once(key, message)
  @warned_keys ||= {}
  return if @warned_keys[key]

  @warned_keys[key] = true
  warn_once_sink(message)
end

#warn_once_sink(msg) ⇒ void

This method returns an undefined value.

Swappable sink for the deprecation message -- a method rather than an attribute so Minitest::Mock#stub(:warn_once_sink, replacement) can intercept it directly: stub invokes the replacement with whatever arguments the stubbed call site passes (here, the message), rather than substituting it as a return value. Defaults to logging via Rails.logger.

Parameters:

  • msg (String)


25
26
27
# File 'lib/admin_suite/deprecation.rb', line 25

def warn_once_sink(msg)
  Rails.logger&.warn(msg)
end