Module: Mongo::Deprecations Private

Extended by:
Deprecations, Loggable
Included in:
Deprecations
Defined in:
lib/mongo/deprecations.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.

Used for reporting deprecated behavior in the driver. When it is possible to detect that a deprecated feature is being used, a warning should be issued through this module.

The warning will be issued no more than once for that feature, regardless of how many times Mongo::Deprecations.warn is called.

Examples:

Issue a deprecation warning.

Mongo::Deprecations.warn(:old_feature, "The old_feature is deprecated, use new_feature instead.")

Constant Summary collapse

MUTEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mutex for synchronizing access to warned features.

Thread::Mutex.new

Constants included from Loggable

Loggable::PREFIX

Instance Method Summary collapse

Methods included from Loggable

log_debug, log_error, log_fatal, log_info, log_warn, logger

Instance Method Details

#clear!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.

Clears all memory of previously warned features.



58
59
60
61
# File 'lib/mongo/deprecations.rb', line 58

def clear!
  MUTEX.synchronize { warned_features reset: true }
  nil
end

#warn(feature, message) ⇒ 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.

Issue a warning about a deprecated feature. The warning is written to the logger, and will not be written more than once per feature.

Parameters:

  • feature (String | Symbol)

    The deprecated feature.

  • message (String)

    The deprecation message.



30
31
32
33
34
35
36
37
# File 'lib/mongo/deprecations.rb', line 30

def warn(feature, message)
  MUTEX.synchronize do
    return if _warned?(feature)

    _warned!(feature)
    log_warn("[DEPRECATION:#{feature}] #{message}")
  end
end

#warned!(feature) ⇒ 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.

Mark that a warning for a given deprecated feature has been issued.

Parameters:

  • feature (String | Symbol)

    The deprecated feature.



52
53
54
55
# File 'lib/mongo/deprecations.rb', line 52

def warned!(feature)
  MUTEX.synchronize { _warned!(feature) }
  nil
end

#warned?(feature, prefix: false) ⇒ 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.

Check if a warning for a given deprecated feature has already been issued.

Parameters:

  • feature (String | Symbol)

    The deprecated feature.

  • prefix (true | false) (defaults to: false)

    Whether to check for prefix matches.

Returns:

  • (true | false)

    If a warning has already been issued.



45
46
47
# File 'lib/mongo/deprecations.rb', line 45

def warned?(feature, prefix: false)
  MUTEX.synchronize { _warned?(feature, prefix: prefix) }
end