Class Index [+]

Quicksearch

ActiveSupport::Deprecation

Constants

DEFAULT_BEHAVIORS

Default warning behaviors per Rails.env.

Attributes

debug[RW]

Whether to print a backtrace along with the warning.

silenced[RW]
deprecation_horizon[RW]

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

Public Class Methods

behavior() click to toggle source

Returns the set behavior or if one isn’t set, defaults to :stderr

    # File lib/active_support/deprecation/behaviors.rb, line 11
11:       def behavior
12:         @behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
13:       end
behavior=(behavior) click to toggle source

Sets the behavior to the specified value. Can be a single value or an array.

Examples

  ActiveSupport::Deprecation.behavior = :stderr
  ActiveSupport::Deprecation.behavior = [:stderr, :log]
    # File lib/active_support/deprecation/behaviors.rb, line 21
21:       def behavior=(behavior)
22:         @behavior = Array.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
23:       end
deprecate_methods(target_module, *method_names) click to toggle source

Declare that a method has been deprecated.

    # File lib/active_support/deprecation/method_wrappers.rb, line 8
 8:     def deprecate_methods(target_module, *method_names)
 9:       options = method_names.extract_options!
10:       method_names += options.keys
11: 
12:       method_names.each do |method_name|
13:         target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
14:           target_module.module_eval(            def #{target}_with_deprecation#{punctuation}(*args, &block)              ::ActiveSupport::Deprecation.warn(                ::ActiveSupport::Deprecation.deprecated_method_warning(                  :#{method_name},                  #{options[method_name].inspect}),                caller              )              send(:#{target}_without_deprecation#{punctuation}, *args, &block)            end, __FILE__, __LINE__ + 1)
15:         end
16:       end
17:     end
deprecated_method_warning(method_name, message = nil) click to toggle source
    # File lib/active_support/deprecation/reporting.rb, line 25
25:       def deprecated_method_warning(method_name, message = nil)
26:         warning = "#{method_name} is deprecated and will be removed from Rails #{deprecation_horizon}"
27:         case message
28:           when Symbol then "#{warning} (use #{message} instead)"
29:           when String then "#{warning} (#{message})"
30:           else warning
31:         end
32:       end
silence() click to toggle source

Silence deprecation warnings within the block.

    # File lib/active_support/deprecation/reporting.rb, line 18
18:       def silence
19:         old_silenced, @silenced = @silenced, true
20:         yield
21:       ensure
22:         @silenced = old_silenced
23:       end
warn(message = nil, callstack = caller) click to toggle source

Outputs a deprecation warning to the output configured by ActiveSupport::Deprecation.behavior

  ActiveSupport::Deprecation.warn("something broke!")
  # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
    # File lib/active_support/deprecation/reporting.rb, line 10
10:       def warn(message = nil, callstack = caller)
11:         return if silenced
12:         deprecation_message(callstack, message).tap do |m|
13:           behavior.each { |b| b.call(m, callstack) }
14:         end
15:       end

Private Class Methods

deprecation_caller_message(callstack) click to toggle source
    # File lib/active_support/deprecation/reporting.rb, line 41
41:         def deprecation_caller_message(callstack)
42:           file, line, method = extract_callstack(callstack)
43:           if file
44:             if line && method
45:               "(called from #{method} at #{file}:#{line})"
46:             else
47:               "(called from #{file}:#{line})"
48:             end
49:           end
50:         end
deprecation_message(callstack, message = nil) click to toggle source
    # File lib/active_support/deprecation/reporting.rb, line 35
35:         def deprecation_message(callstack, message = nil)
36:           message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
37:           message += '.' unless message =~ /\.$/
38:           "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
39:         end
extract_callstack(callstack) click to toggle source
    # File lib/active_support/deprecation/reporting.rb, line 52
52:         def extract_callstack(callstack)
53:           rails_gem_root = File.expand_path("../../../../..", __FILE__) + "/"
54:           offending_line = callstack.find { |line| !line.start_with?(rails_gem_root) } || callstack.first
55:           if offending_line
56:             if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
57:               md.captures
58:             else
59:               offending_line
60:             end
61:           end
62:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.