跳至内容 跳至搜索

已弃用警告的托管集合。配置方法,例如 behavior=,会影响集合中的所有已弃用警告。此外,silence 方法会在给定代码块的持续时间内静默集合中的所有已弃用警告。

方法
#
B
D
E
N
S

类公共方法

new()

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 10
def initialize
  @options = {}
  @deprecators = {}
end

实例公共方法

[](name)

返回通过 []= 添加到此集合中的已弃用警告。

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 16
def [](name)
  @deprecators[name]
end

[]=(name, deprecator)

将给定的 deprecator 添加到此集合。该已弃用警告将立即使用此集合中先前设置的任何选项进行配置。

deprecators = ActiveSupport::Deprecation::Deprecators.new
deprecators.debug = true

foo_deprecator = ActiveSupport::Deprecation.new("2.0", "Foo")
foo_deprecator.debug    # => false

deprecators[:foo] = foo_deprecator
deprecators[:foo].debug # => true
foo_deprecator.debug    # => true
# File activesupport/lib/active_support/deprecation/deprecators.rb, line 34
def []=(name, deprecator)
  apply_options(deprecator)
  @deprecators[name] = deprecator
end

behavior=(behavior)

为集合中的所有已弃用警告设置已弃用警告行为。

请参阅 ActiveSupport::Deprecation#behavior=

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 60
def behavior=(behavior)
  set_option(:behavior, behavior)
end

debug=(debug)

为集合中的所有已弃用警告设置调试标志。

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 52
def debug=(debug)
  set_option(:debug, debug)
end

disallowed_behavior=(disallowed_behavior)

为集合中的所有已弃用警告设置不允许的已弃用警告行为。

请参阅 ActiveSupport::Deprecation#disallowed_behavior=

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 68
def disallowed_behavior=(disallowed_behavior)
  set_option(:disallowed_behavior, disallowed_behavior)
end

disallowed_warnings=(disallowed_warnings)

为集合中的所有已弃用警告设置不允许的已弃用警告。

请参阅 ActiveSupport::Deprecation#disallowed_warnings=

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 76
def disallowed_warnings=(disallowed_warnings)
  set_option(:disallowed_warnings, disallowed_warnings)
end

each(&block)

遍历集合中的所有已弃用警告。如果没有提供块,则返回一个 Enumerator

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 41
def each(&block)
  return to_enum(__method__) unless block
  @deprecators.each_value(&block)
end

silence(&block)

在给定代码块的持续时间内静默集合中的所有已弃用警告。

请参阅 ActiveSupport::Deprecation#silence

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 84
def silence(&block)
  each { |deprecator| deprecator.begin_silence }
  block.call
ensure
  each { |deprecator| deprecator.end_silence }
end

silenced=(silenced)

为集合中的所有已弃用警告设置静默标志。

# File activesupport/lib/active_support/deprecation/deprecators.rb, line 47
def silenced=(silenced)
  set_option(:silenced, silenced)
end