Module: CMDx::Deprecator

Extended by:
Deprecator
Included in:
Deprecator
Defined in:
lib/cmdx/deprecator.rb

Overview

Handles deprecation warnings and restrictions for tasks.

The Deprecator module provides functionality to restrict usage of deprecated tasks based on configuration settings. It supports different deprecation behaviors including warnings, logging, and errors.

Instance Method Summary collapse

Instance Method Details

#restrict(task) ⇒ Object

Restricts task usage based on deprecation settings.

Examples:

class MyTask
  settings(deprecate: :warn)
end

MyTask.new # => [MyTask] DEPRECATED: migrate to a replacement or discontinue use

Parameters:

  • task (Object)

    The task object to check for deprecation

  • task.class.settings.deprecate (Hash)

    a customizable set of options

Raises:

  • (DeprecationError)

    When deprecation type is :raise or true

  • (RuntimeError)

    When deprecation type is unknown

Rbs:

  • (Task task) -> void



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cmdx/deprecator.rb', line 63

def restrict(task)
  setting = task.class.settings.deprecate
  return unless setting

  case type = EVAL.call(task, setting)
  when NilClass, FalseClass then nil # Do nothing
  when TrueClass, RAISE_REGEXP then raise DeprecationError, "#{task.class.name} usage prohibited"
  when LOG_REGEXP then task.logger.warn { "DEPRECATED: migrate to a replacement or discontinue use" }
  when WARN_REGEXP then warn("[#{task.class.name}] DEPRECATED: migrate to a replacement or discontinue use", category: :deprecated)
  else raise "unknown deprecation type #{type.inspect}"
  end
end