123456789_123456789_123456789_123456789_123456789_

Module: Mongo::Deprecations Private

Do not use. This module is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Loggable, self
Defined in: lib/mongo/deprecations.rb

Overview

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 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

Class Method Summary

Loggable - Extended

log_debug

Convenience method to log debug messages with the standard prefix.

log_error

Convenience method to log error messages with the standard prefix.

log_fatal

Convenience method to log fatal messages with the standard prefix.

log_info

Convenience method to log info messages with the standard prefix.

log_warn

Convenience method to log warn messages with the standard prefix.

logger

Get the logger instance.

_mongo_log_prefix, format_message

Instance Method Summary

Instance Method Details

#_warned!(feature) (private)

Mark that a warning for a given deprecated feature has been issued. This version is not thread-safe.

Parameters:

  • feature (String | Symbol)

    The deprecated feature.

[ GitHub ]

  
# File 'lib/mongo/deprecations.rb', line 94

def _warned!(feature)
  warned_features.add(feature.to_s)
end

#_warned?(feature, prefix: false) ⇒ true | false (private)

Check if a warning for a given deprecated feature has already been issued. This version is not thread-safe.

Parameters:

  • feature (String | Symbol)

    The deprecated feature.

  • prefix (true | false)

    Whether to check for prefix matches.

Returns:

  • (true | false)

    If a warning has already been issued.

[ GitHub ]

  
# File 'lib/mongo/deprecations.rb', line 82

def _warned?(feature, prefix: false)
  if prefix
    warned_features.any? { |f| f.to_s.start_with?(feature) }
  else
    warned_features.include?(feature.to_s)
  end
end

#clear!

Clears all memory of previously warned features.

[ GitHub ]

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

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

#warn(feature, message)

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.

[ GitHub ]

  
# 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)

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

Parameters:

  • feature (String | Symbol)

    The deprecated feature.

[ GitHub ]

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

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

#warned?(feature, prefix: false) ⇒ true | false

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

Parameters:

  • feature (String | Symbol)

    The deprecated feature.

  • prefix (true | false)

    Whether to check for prefix matches.

Returns:

  • (true | false)

    If a warning has already been issued.

[ GitHub ]

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

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

#warned_features(reset: false) ⇒ Set<String> (private)

Set of features that have already been warned about.

Parameters:

  • reset (true | false)

    Whether to reset the warned features.

Returns:

  • (Set<String>)

    The set of warned features.

[ GitHub ]

  
# File 'lib/mongo/deprecations.rb', line 70

def warned_features(reset: false)
  @warned_features = nil if reset
  @warned_features ||= Set.new
end