Class: ActiveSupport::Deprecation

Inherits:
Object
  • Object
show all
Includes:
Behavior, Disallowed, InstanceDelegator, MethodWrapper, Reporting, Singleton
Defined in:
lib/active_support/deprecation.rb,
lib/active_support/deprecation/behaviors.rb,
lib/active_support/deprecation/reporting.rb,
lib/active_support/deprecation/disallowed.rb,
lib/active_support/deprecation/proxy_wrappers.rb,
lib/active_support/deprecation/method_wrappers.rb,
lib/active_support/deprecation/constant_accessor.rb,
lib/active_support/deprecation/instance_delegator.rb

Overview

Deprecation specifies the API used by Rails to deprecate methods, instance variables, objects and constants.

Defined Under Namespace

Modules: Behavior, DeprecatedConstantAccessor, Disallowed, InstanceDelegator, MethodWrapper, Reporting Classes: DeprecatedConstantProxy, DeprecatedInstanceVariableProxy, DeprecatedObjectProxy, DeprecationProxy

Constant Summary collapse

DEFAULT_BEHAVIORS =

Default warning behaviors per Rails.env.

{
  raise: ->(message, callstack, deprecation_horizon, gem_name) {
    e = DeprecationException.new(message)
    e.set_backtrace(callstack.map(&:to_s))
    raise e
  },

  stderr: ->(message, callstack, deprecation_horizon, gem_name) {
    $stderr.puts(message)
    $stderr.puts callstack.join("\n  ") if debug
  },

  log: ->(message, callstack, deprecation_horizon, gem_name) {
    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 debug
  },

  notify: ->(message, callstack, deprecation_horizon, gem_name) {
    notification_name = "deprecation.#{gem_name.underscore.tr('/', '_')}"
    ActiveSupport::Notifications.instrument(notification_name,
                                            message: message,
                                            callstack: callstack,
                                            gem_name: gem_name,
                                            deprecation_horizon: deprecation_horizon)
  },

  silence: ->(message, callstack, deprecation_horizon, gem_name) { },
}

Instance Attribute Summary collapse

Attributes included from Disallowed

#disallowed_warnings

Attributes included from Reporting

#gem_name, #silenced

Attributes included from Behavior

#debug

Instance Method Summary collapse

Methods included from MethodWrapper

#deprecate_methods

Methods included from Reporting

#allow, #deprecation_warning, #silence, #warn

Methods included from Behavior

#behavior, #behavior=, #disallowed_behavior, #disallowed_behavior=

Methods included from InstanceDelegator

included

Methods included from Singleton

#duplicable?

Constructor Details

#initialize(deprecation_horizon = "7.1", gem_name = "Rails") ⇒ Deprecation

It accepts two parameters on initialization. The first is a version of library and the second is a library name.

ActiveSupport::Deprecation.new('2.0', 'MyLibrary')


41
42
43
44
45
46
47
48
49
# File 'lib/active_support/deprecation.rb', line 41

def initialize(deprecation_horizon = "7.1", 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
  @silenced_thread = Concurrent::ThreadLocalVar.new(false)
  @explicitly_allowed_warnings = Concurrent::ThreadLocalVar.new(nil)
end

Instance Attribute Details

#deprecation_horizonObject

The version number in which the deprecated behavior will be removed, by default.



35
36
37
# File 'lib/active_support/deprecation.rb', line 35

def deprecation_horizon
  @deprecation_horizon
end