模块 Gem::Deprecate
公共类方法
rubygems_deprecate(name, replacement=:none) 点击切换源代码
简单的弃用方法,通过将 name
封装在一个虚拟方法中来弃用它。每次调用虚拟方法时都会发出警告,告诉用户 repl
(除非 repl
为 :none) 以及计划删除它的 Rubygems 版本。
# File rubygems/deprecate.rb, line 129 def rubygems_deprecate(name, replacement=:none) class_eval do old = "_deprecated_#{name}" alias_method old, name define_method name do |*args, &block| klass = is_a? Module target = klass ? "#{self}." : "#{self.class}#" msg = [ "NOTE: #{target}#{name} is deprecated", replacement == :none ? " with no replacement" : "; use #{replacement} instead", ". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}", "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", ] warn "#{msg.join}." unless Gem::Deprecate.skip send old, *args, &block end ruby2_keywords name if respond_to?(:ruby2_keywords, true) end end
rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) 点击切换源代码
用于弃用 Rubygems 命令的弃用方法
# File rubygems/deprecate.rb, line 150 def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) class_eval do define_method "deprecated?" do true end define_method "deprecation_warning" do msg = [ "#{command} command is deprecated", ". It will be removed in Rubygems #{version}.\n", ] alert_warning msg.join.to_s unless Gem::Deprecate.skip end end end
skip_during() { || ... } 点击切换源代码
暂时关闭警告。仅用于测试。
# File rubygems/deprecate.rb, line 85 def skip_during original = Gem::Deprecate.skip Gem::Deprecate.skip = true yield ensure Gem::Deprecate.skip = original end
公共实例方法
deprecate(name, repl, year, month) 点击切换源代码
简单的弃用方法,通过将 name
封装在一个虚拟方法中来弃用它。每次调用虚拟方法时都会发出警告,告诉用户 repl
(除非 repl
为 :none) 以及计划删除它的年份/月份。
# File rubygems/deprecate.rb, line 103 def deprecate(name, repl, year, month) class_eval do old = "_deprecated_#{name}" alias_method old, name define_method name do |*args, &block| klass = is_a? Module target = 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}." unless Gem::Deprecate.skip send old, *args, &block end ruby2_keywords name if respond_to?(:ruby2_keywords, true) end end
私有实例方法
rubygems_deprecate(name, replacement=:none) 点击切换源代码
简单的弃用方法,通过将 name
封装在一个虚拟方法中来弃用它。每次调用虚拟方法时都会发出警告,告诉用户 repl
(除非 repl
为 :none) 以及计划删除它的 Rubygems 版本。
# File rubygems/deprecate.rb, line 129 def rubygems_deprecate(name, replacement=:none) class_eval do old = "_deprecated_#{name}" alias_method old, name define_method name do |*args, &block| klass = is_a? Module target = klass ? "#{self}." : "#{self.class}#" msg = [ "NOTE: #{target}#{name} is deprecated", replacement == :none ? " with no replacement" : "; use #{replacement} instead", ". It will be removed in Rubygems #{Gem::Deprecate.next_rubygems_major_version}", "\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", ] warn "#{msg.join}." unless Gem::Deprecate.skip send old, *args, &block end ruby2_keywords name if respond_to?(:ruby2_keywords, true) end end
rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) 点击切换源代码
用于弃用 Rubygems 命令的弃用方法
# File rubygems/deprecate.rb, line 150 def rubygems_deprecate_command(version = Gem::Deprecate.next_rubygems_major_version) class_eval do define_method "deprecated?" do true end define_method "deprecation_warning" do msg = [ "#{command} command is deprecated", ". It will be removed in Rubygems #{version}.\n", ] alert_warning msg.join.to_s unless Gem::Deprecate.skip end end end
skip_during() { || ... } 点击切换源代码
暂时关闭警告。仅用于测试。
# File rubygems/deprecate.rb, line 85 def skip_during original = Gem::Deprecate.skip Gem::Deprecate.skip = true yield ensure Gem::Deprecate.skip = original end