Module: ActiveSupport::Deprecation::ClassMethods

Included in:
Module
Defined in:
lib/active_support/deprecation.rb

Instance Method Summary collapse

Instance Method Details

#deprecate(*method_names) ⇒ Object

Declare that a method has been deprecated.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/active_support/deprecation.rb', line 86

def deprecate(*method_names)
  options = method_names.last.is_a?(Hash) ? method_names.pop : {}
  method_names = method_names + options.keys
  method_names.each do |method_name|
    alias_method_chain(method_name, :deprecation) do |target, punctuation|
      class_eval(<<-EOS, __FILE__, __LINE__)
        def #{target}_with_deprecation#{punctuation}(*args, &block)
          ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller)
          #{target}_without_deprecation#{punctuation}(*args, &block)
        end
      EOS
    end
  end
end

#deprecated_method_warning(method_name, message = nil) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/active_support/deprecation.rb', line 101

def deprecated_method_warning(method_name, message=nil)
  warning = "#{method_name} is deprecated and will be removed from Rails #{deprecation_horizon}"
  case message
    when Symbol then "#{warning} (use #{message} instead)"
    when String then "#{warning} (#{message})"
    else warning
  end
end

#deprecation_horizonObject



110
111
112
# File 'lib/active_support/deprecation.rb', line 110

def deprecation_horizon
  '2.0'
end