Module: ActiveSupport::Deprecation

Defined in:
lib/active_support/deprecation.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Assertions, ClassMethods Classes: DeprecatedInstanceVariableProxy

Constant Summary collapse

DEFAULT_BEHAVIORS =

Choose the default warn behavior according to RAILS_ENV. Ignore deprecation warnings in production.

{
  'test'        => Proc.new { |message, callstack|
                     $stderr.puts(message)
                     $stderr.puts callstack.join("\n  ") if debug
                   },
  'development' => Proc.new { |message, callstack|
                     logger = defined?(::RAILS_DEFAULT_LOGGER) ? ::RAILS_DEFAULT_LOGGER : Logger.new($stderr)
                     logger.warn message
                     logger.debug callstack.join("\n  ") if debug
                   }
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.silenced=(value) ⇒ Object (writeonly)

Sets the attribute silenced

Parameters:

  • value

    the value to set the attribute silenced to.


49
50
51
# File 'lib/active_support/deprecation.rb', line 49

def silenced=(value)
  @silenced = value
end

Class Method Details

.default_behaviorObject


27
28
29
30
31
32
33
# File 'lib/active_support/deprecation.rb', line 27

def default_behavior
  if defined?(RAILS_ENV)
    DEFAULT_BEHAVIORS[RAILS_ENV.to_s]
  else
    DEFAULT_BEHAVIORS['test']
  end
end

.silenceObject

Silence deprecation warnings within the block.


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

def silence
  old_silenced, @silenced = @silenced, true
  yield
ensure
  @silenced = old_silenced
end

.silenced?Boolean

Have deprecations been silenced?

Returns:

  • (Boolean)

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

def silenced?
  @silenced = false unless defined?(@silenced)
  @silenced
end

.warn(message = nil, callstack = caller) ⇒ Object


23
24
25
# File 'lib/active_support/deprecation.rb', line 23

def warn(message = nil, callstack = caller)
  behavior.call(deprecation_message(callstack, message), callstack) if behavior && !silenced?
end