Module: Autoloaded::Warning Private

Defined in:
lib/autoloaded/warning.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 warning 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 warning stream. Defaults to $stderr.

Returns:

  • (IO)

    the warning stream

Since:

  • 1.3



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

def io
  @io || $stderr
end

Class Method Details

.changing_autoload(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 warning message to #io concerning an existing autoloaded constant for which the autoloaded source file is being changed.

Parameters:

  • keywords (Hash)

    the parameters of the warning message

Options Hash (keywords):

  • :constant_name (Symbol)

    the name of the constant

  • :old_source_filename (String)

    the name of the existing autoloaded source file

  • :new_source_filename (String)

    the name of the new autoloaded source file

  • :host_source_location (String)

    the file and line number of the source establishing autoloading

Returns:

  • (Module)

    Warning

Raises:

  • (ArgumentError)

    one or more keywords are missing

Since:

  • 1.3



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/autoloaded/warning.rb', line 38

def changing_autoload(keywords)
  constant_name        = fetch(keywords, :constant_name)
  old_source_filename  = fetch(keywords, :old_source_filename)
  new_source_filename  = fetch(keywords, :new_source_filename)
  host_source_location = fetch(keywords, :host_source_location)

  message = "Existing autoload of \e[4m#{constant_name}\e[0m from "       +
            "#{old_source_filename.inspect} is being overridden to "      +
            "autoload from #{new_source_filename.inspect} -- avoid this " +
            "warning by using an \e[4monly\e[0m or an \e[4mexcept\e[0m "  +
            "specification in the block at #{host_source_location}"
  warn message
end

.enable(enabling) { ... } ⇒ 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.

Enables or disables warning messages depending on the specified enabling argument.

Parameters:

  • enabling (Object)

    disables warnings if nil or false

Yields:

  • if a block is given, the value of #enabled? is reset after the block is called

Returns:

  • if a block is given, the result of calling the block

  • (Module)

    if a block is not given, Warning

See Also:

Since:

  • 1.3



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/autoloaded/warning.rb', line 64

def enable(enabling)
  previous_value = instance_variable_defined?(:@disabled) && @disabled
  @disabled = not!(enabling)
  if block_given?
    begin
      return yield
    ensure
      @disabled = previous_value
    end
  end

  self
end

.enabled?true, false

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.

Indicates whether warning messages are enabled or disabled.

Returns:

  • (true)

    if warning messages are enabled

  • (false)

    if warning messages are enabled

See Also:

Since:

  • 1.3



84
85
86
# File 'lib/autoloaded/warning.rb', line 84

def enabled?
  not! @disabled
end

.existing_constant(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 warning message to #io concerning a defined constant for which autoloading is being established.

Parameters:

  • keywords (Hash)

    the parameters of the warning message

Options Hash (keywords):

  • :constant_name (Symbol)

    the name of the constant

  • :source_filename (String)

    the name of the autoloaded source file

  • :host_source_location (String)

    the file and line number of the source establishing autoloading

Returns:

  • (Module)

    Warning

Raises:

  • (ArgumentError)

    one or more keywords are missing

Since:

  • 1.3



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/autoloaded/warning.rb', line 102

def existing_constant(keywords)
  constant_name        = fetch(keywords, :constant_name)
  source_filename      = fetch(keywords, :source_filename)
  host_source_location = fetch(keywords, :host_source_location)

  message = "Existing definition of \e[4m#{constant_name}\e[0m obviates " +
            "autoloading from #{source_filename.inspect} -- avoid this "  +
            "warning by using an \e[4monly\e[0m or an \e[4mexcept\e[0m "  +
            "specification in the block at #{host_source_location}"
  warn message
end