Module: Autoloaded::Deprecation Private

Defined in:
lib/autoloaded/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.

Prints deprecation messages to stderr.

Since:

  • 1.3

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ioIO

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.

The deprecation stream. Defaults to $stderr.

Returns:

  • (IO)

    the deprecation stream

Since:

  • 1.3



18
19
20
# File 'lib/autoloaded/deprecation.rb', line 18

def io
  @io || $stderr
end

Class Method Details

.deprecate(keywords) ⇒ Module

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.

Prints a deprecation message to #io regarding the specified deprecated_usage.

Parameters:

  • keywords (Hash)

    the parameters of the deprecation message

Options Hash (keywords):

  • :deprecated_usage (String)

    API usage that is soon to be discontinued

  • :sanctioned_usage (String)

    API usage that will succeed :deprecated_usage

  • :source_filename (String)

    the file path of the source invoking the deprecated API

Returns:

  • (Module)

    Deprecation

Raises:

  • (ArgumentError)

    one or more keywords are missing

Since:

  • 1.3



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/autoloaded/deprecation.rb', line 36

def deprecate(keywords)
  deprecated_usage = fetch(keywords, :deprecated_usage)
  sanctioned_usage = fetch(keywords, :sanctioned_usage)
  source_filename  = fetch(keywords, :source_filename)

  deprecation = "\e[33m*** \e[7m DEPRECATED \e[0m "     +
                "\e[4m#{deprecated_usage}\e[0m -- use " +
                "\e[4m#{sanctioned_usage}\e[0m instead in #{source_filename}"
  io.puts deprecation

  self
end