diff options
author | Michael Koziarski <michael@koziarski.com> | 2006-07-27 00:10:06 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2006-07-27 00:10:06 +0000 |
commit | 7692191f5ab207ff76cc2558f2a02e299cd51392 (patch) | |
tree | 10c7e0a5ee77351e5c114cb6e6c8dae9d3a5cf1a /activesupport/lib/active_support/deprecation.rb | |
parent | 45e319d0f81b8e97bee69ced1db5636075b38f1d (diff) | |
download | rails-7692191f5ab207ff76cc2558f2a02e299cd51392.tar.gz rails-7692191f5ab207ff76cc2558f2a02e299cd51392.tar.bz2 rails-7692191f5ab207ff76cc2558f2a02e299cd51392.zip |
Initial Version of Deprecation for Rails[Koz]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4623 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/deprecation.rb')
-rw-r--r-- | activesupport/lib/active_support/deprecation.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb new file mode 100644 index 0000000000..a72b12bcfe --- /dev/null +++ b/activesupport/lib/active_support/deprecation.rb @@ -0,0 +1,46 @@ +module ActiveSupport + module Deprecation + @@warning_method = :print + mattr_accessor :warning_method + + class << self + + def print_warning(lines) + lines.each {|l| $stderr.write("#{l}\n")} + end + + def log_warning(lines) + if Object.const_defined?("RAILS_DEFAULT_LOGGER") + lines.each {|l| RAILS_DEFAULT_LOGGER.warn l} + else + print_warning(lines) + end + end + + def issue_warning(line) + lines = + ["@@@@@@@@@@ Deprecation Warning @@@@@@@@@@", line, + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"] + self.send("#{@@warning_method}_warning", lines) + end + + def instance_method_warning(clazz, method) + issue_warning("Your application calls #{clazz}##{method}, which is now deprecated. Please see the API documents at http://api.rubyonrails.org/ for more information.") + end + end + + module ClassMethods + def deprecate(method_name) + alias_method "#{method_name}_before_deprecation", method_name + class_eval(<<-EOS, __FILE__, __LINE__) + def #{method_name}(*args) + ::ActiveSupport::Deprecation.instance_method_warning(self.class, :#{method_name}) + #{method_name}_before_deprecation *args + end + EOS + end + end + end +end + +Object.extend(ActiveSupport::Deprecation::ClassMethods) |