Module: Mongoid::Deprecable Private

Included in:
Mongoid
Defined in:
lib/mongoid/deprecable.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.

Adds ability to declare Mongoid-specific deprecations.

Instance Method Summary collapse

Instance Method Details

#deprecate(target_module, *method_descriptors) ⇒ 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.

Declares method(s) as deprecated.

Examples:

Deprecate a method.

Mongoid.deprecate(Cat, :meow); Cat.new.meow
#=> Mongoid.logger.warn("meow is deprecated and will be removed from Mongoid 8.0")

Deprecate a method and declare the replacement method.

Mongoid.deprecate(Cat, meow: :speak); Cat.new.meow
#=> Mongoid.logger.warn("meow is deprecated and will be removed from Mongoid 8.0 (use speak instead)")

Deprecate a method and give replacement instructions.

Mongoid.deprecate(Cat, meow: 'eat :catnip instead'); Cat.new.meow
#=> Mongoid.logger.warn("meow is deprecated and will be removed from Mongoid 8.0 (eat :catnip instead)")


50
51
52
# File 'lib/mongoid/deprecable.rb', line 50

def deprecate(target_module, *method_descriptors)
  deprecator.deprecate_methods(target_module, *method_descriptors)
end

#deprecation_warning(id, warning, callstack = nil) ⇒ 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.

Emits a warning using the current deprecator. If the given warning (as identified by id) has already been issued previously, this is a no-op.



26
27
28
29
30
31
# File 'lib/mongoid/deprecable.rb', line 26

def deprecation_warning(id, warning, callstack = nil)
  site = callstack&.first
  deprecation_warning_guard(id, site ? "#{site.path}:#{site.lineno}" : nil) do
    deprecator.warn(warning, callstack)
  end
end

#deprecatorObject

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.

A Mongoid::Deprecation instance to use for reporting deprecations



11
12
13
# File 'lib/mongoid/deprecable.rb', line 11

def deprecator
  @deprecator ||= Mongoid::Deprecation.new
end

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

Resets all deprecation warnings. For use in tests.



16
17
18
# File 'lib/mongoid/deprecable.rb', line 16

def reset_deprecation_warnings!
  DEPRECATION_WARNING_MUTEX.synchronize { @deprecation_warnings = {} }
end