Skip to content
Newer
Older
100644 47 lines (39 sloc) 1.35 KB
7692191 @NZKoz Initial Version of Deprecation for Rails[Koz]
NZKoz authored Jul 27, 2006
1 module ActiveSupport
2 module Deprecation
3 @@warning_method = :print
4 mattr_accessor :warning_method
5
6 class << self
7
8 def print_warning(lines)
9 lines.each {|l| $stderr.write("#{l}\n")}
10 end
11
12 def log_warning(lines)
13 if Object.const_defined?("RAILS_DEFAULT_LOGGER")
14 lines.each {|l| RAILS_DEFAULT_LOGGER.warn l}
15 else
16 print_warning(lines)
17 end
18 end
19
20 def issue_warning(line)
21 lines =
22 ["@@@@@@@@@@ Deprecation Warning @@@@@@@@@@", line,
23 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"]
24 self.send("#{@@warning_method}_warning", lines)
25 end
26
27 def instance_method_warning(clazz, method)
28 issue_warning("Your application calls #{clazz}##{method}, which is now deprecated. Please see the API documents at http://api.rubyonrails.org/ for more information.")
29 end
30 end
31
32 module ClassMethods
33 def deprecate(method_name)
34 alias_method "#{method_name}_before_deprecation", method_name
35 class_eval(<<-EOS, __FILE__, __LINE__)
36 def #{method_name}(*args)
37 ::ActiveSupport::Deprecation.instance_method_warning(self.class, :#{method_name})
38 #{method_name}_before_deprecation *args
39 end
40 EOS
41 end
42 end
43 end
44 end
45
46 Object.extend(ActiveSupport::Deprecation::ClassMethods)
Something went wrong with that request. Please try again.