Active Support Deprecation¶ ↑
Deprecation 指定了 Rails 用于废弃方法、实例变量、对象和常量所使用的 API。它也可供 gem 或应用程序使用。
对于 gem,请使用 Deprecation.new 创建一个 Deprecation 对象,并将其存储在您的模块或类中(以便用户能够配置它)。
module MyLibrary def self.deprecator @deprecator ||= ActiveSupport::Deprecation.new("2.0", "MyLibrary") end end
对于 Railtie 或 Engine,您可能还希望将其添加到应用程序的 deprecator 中,以便应用程序的配置可以应用于它。
module MyLibrary class Railtie < Rails::Railtie initializer "my_library.deprecator" do |app| app.deprecators[:my_library] = MyLibrary.deprecator end end end
通过上面的初始化器,类似以下的配置设置将影响 MyLibrary.deprecator
# in config/environments/test.rb config.active_support.deprecation = :raise
命名空间
- 模块 ActiveSupport::Deprecation::Behavior
- 模块 ActiveSupport::Deprecation::DeprecatedConstantAccessor
- 模块 ActiveSupport::Deprecation::Disallowed
- 模块 ActiveSupport::Deprecation::MethodWrapper
- 模块 ActiveSupport::Deprecation::Reporting
- 类 ActiveSupport::Deprecation::DeprecatedConstantProxy
- 类 ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy
- 类 ActiveSupport::Deprecation::DeprecatedObjectProxy
- 类 ActiveSupport::Deprecation::Deprecators
方法
- N
包含的模块
- ActiveSupport::Deprecation::Behavior
- ActiveSupport::Deprecation::Reporting
- ActiveSupport::Deprecation::Disallowed
- ActiveSupport::Deprecation::MethodWrapper
常量
| DEFAULT_BEHAVIORS | = | { raise: ->(message, callstack, deprecator) do e = DeprecationException.new(message) e.set_backtrace(callstack.map(&:to_s)) raise e end, stderr: ->(message, callstack, deprecator) do $stderr.puts(message) $stderr.puts callstack.join("\n ") if deprecator.debug end, log: ->(message, callstack, deprecator) do logger = if defined?(Rails.logger) && Rails.logger Rails.logger else require "active_support/logger" ActiveSupport::Logger.new($stderr) end logger.warn message logger.debug callstack.join("\n ") if deprecator.debug end, notify: ->(message, callstack, deprecator) do ActiveSupport::Notifications.instrument( "deprecation.#{deprecator.gem_name.underscore.tr("/", "_")}", message: message, callstack: callstack, gem_name: deprecator.gem_name, deprecation_horizon: deprecator.deprecation_horizon, ) end, silence: ->(message, callstack, deprecator) { }, report: ->(message, callstack, deprecator) do error = DeprecationException.new(message) error.set_backtrace(callstack.map(&:to_s)) ActiveSupport.error_reporter.report(error) end } |
每个 |
||
Attributes
| [RW] | deprecation_horizon | 默认情况下,已废弃的行为将被移除的版本号。 |
类公共方法
new(deprecation_horizon = "8.2", gem_name = "Rails") 链接
它在初始化时接受两个参数。第一个是库的版本,第二个是库的名称。
ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/deprecation.rb, line 71 def initialize(deprecation_horizon = "8.2", gem_name = "Rails") self.gem_name = gem_name self.deprecation_horizon = deprecation_horizon # By default, warnings are not silenced and debugging is off. self.silenced = false self.debug = false @silence_counter = Concurrent::ThreadLocalVar.new(0) @explicitly_allowed_warnings = Concurrent::ThreadLocalVar.new(nil) end