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



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cmdx/deprecator.rb', line 51

def restrict(task)
  type = EVAL.call(task, task.class.settings[:deprecate])

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