1. Gem::
  2. Deprecate

module Gem::Deprecate

Provides 3 methods for declaring when something is going away.

deprecate(name, repl, year, month):

Indicate something may be removed on/after a certain date.

rubygems_deprecate(name, replacement=:none):

Indicate something will be removed in the next major RubyGems version,and (optionally) a replacement for it.

rubygems_deprecate_command:

Indicate a RubyGems command (in +lib/rubygems/commands/*.rb+) will beremoved in the next RubyGems version.

Also providesskip_during for temporarily turning off deprecation warnings. This is intended to be used in the test suite, so deprecation warnings don’t cause test failures if you need to make sure stderr is otherwise empty.

Example usage ofdeprecate andrubygems_deprecate:

classLegacydefself.some_class_method# ...enddefsome_instance_method# ...enddefsome_old_method# ...endextendGem::Deprecatedeprecate:some_instance_method,"X.z",2011,4rubygems_deprecate:some_old_method,"Modern#some_new_method"class<<selfextendGem::Deprecatedeprecate:some_class_method,:none,2011,4endend

Example usage ofrubygems_deprecate_command:

classGem::Commands::QueryCommand<Gem::CommandextendGem::Deprecaterubygems_deprecate_command# ...end

Example usage ofskip_during:

classTestSomething<Gem::Testcasedeftest_some_thing_with_deprecationsGem::Deprecate.skip_duringdoactual_stdout,actual_stderr =capture_outputdoGem.something_deprecatedendassert_emptyactual_stdoutassert_equal(expected,actual_stderr)endendend

Public Class Methods

Source
# File lib/rubygems/deprecate.rb, line 129defrubygems_deprecate(name,replacement =:none,version =nil)class_evaldoold ="_deprecated_#{name}"alias_methodold,namedefine_methodnamedo|*args,&block|klass =is_a?Moduletarget =klass?"#{self}.":"#{self.class}#"version||=Gem::Deprecate.next_rubygems_major_versionmsg = ["NOTE: #{target}#{name} is deprecated",replacement==:none?" with no replacement":"; use #{replacement} instead",". It will be removed in Rubygems #{version}","\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",      ]warn"#{msg.join}."unlessGem::Deprecate.skipsendold,*args,&blockendruby2_keywordsnameifrespond_to?(:ruby2_keywords,true)endend

Simple deprecation method that deprecatesname by wrapping it up in a dummy method. It warns on each call to the dummy method telling the user ofrepl (unlessrepl is :none) and the Rubygems version that it is planned to go away.

Source
# File lib/rubygems/deprecate.rb, line 151defrubygems_deprecate_command(version =nil)class_evaldodefine_method"deprecated?"dotrueenddefine_method"deprecation_warning"doversion||=Gem::Deprecate.next_rubygems_major_versionmsg = ["#{command} command is deprecated",". It will be removed in Rubygems #{version}.\n",      ]alert_warningmsg.join.to_sunlessGem::Deprecate.skipendendend

Deprecation method to deprecate Rubygems commands

Source
# File lib/rubygems/deprecate.rb, line 85defskip_duringoriginal =Gem::Deprecate.skipGem::Deprecate.skip =trueyieldensureGem::Deprecate.skip =originalend

Temporarily turn off warnings. Intended for tests only.

Public Instance Methods

Source
# File lib/rubygems/deprecate.rb, line 103defdeprecate(name,repl,year,month)class_evaldoold ="_deprecated_#{name}"alias_methodold,namedefine_methodnamedo|*args,&block|klass =is_a?Moduletarget =klass?"#{self}.":"#{self.class}#"msg = ["NOTE: #{target}#{name} is deprecated",repl==:none?" with no replacement":"; use #{repl} instead",format(". It will be removed on or after %4d-%02d.",year,month),"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",      ]warn"#{msg.join}."unlessGem::Deprecate.skipsendold,*args,&blockendruby2_keywordsnameifrespond_to?(:ruby2_keywords,true)endend

Simple deprecation method that deprecatesname by wrapping it up in a dummy method. It warns on each call to the dummy method telling the user ofrepl (unlessrepl is :none) and the year/month that it is planned to go away.

Private Instance Methods

Source
# File lib/rubygems/deprecate.rb, line 129defrubygems_deprecate(name,replacement =:none,version =nil)class_evaldoold ="_deprecated_#{name}"alias_methodold,namedefine_methodnamedo|*args,&block|klass =is_a?Moduletarget =klass?"#{self}.":"#{self.class}#"version||=Gem::Deprecate.next_rubygems_major_versionmsg = ["NOTE: #{target}#{name} is deprecated",replacement==:none?" with no replacement":"; use #{replacement} instead",". It will be removed in Rubygems #{version}","\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}",      ]warn"#{msg.join}."unlessGem::Deprecate.skipsendold,*args,&blockendruby2_keywordsnameifrespond_to?(:ruby2_keywords,true)endend

Simple deprecation method that deprecatesname by wrapping it up in a dummy method. It warns on each call to the dummy method telling the user ofrepl (unlessrepl is :none) and the Rubygems version that it is planned to go away.

Source
# File lib/rubygems/deprecate.rb, line 151defrubygems_deprecate_command(version =nil)class_evaldodefine_method"deprecated?"dotrueenddefine_method"deprecation_warning"doversion||=Gem::Deprecate.next_rubygems_major_versionmsg = ["#{command} command is deprecated",". It will be removed in Rubygems #{version}.\n",      ]alert_warningmsg.join.to_sunlessGem::Deprecate.skipendendend

Deprecation method to deprecate Rubygems commands

Source
# File lib/rubygems/deprecate.rb, line 85defskip_duringoriginal =Gem::Deprecate.skipGem::Deprecate.skip =trueyieldensureGem::Deprecate.skip =originalend

Temporarily turn off warnings. Intended for tests only.