From 7692191f5ab207ff76cc2558f2a02e299cd51392 Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Thu, 27 Jul 2006 00:10:06 +0000 Subject: Initial Version of Deprecation for Rails[Koz] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4623 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support.rb | 1 + activesupport/lib/active_support/deprecation.rb | 46 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 activesupport/lib/active_support/deprecation.rb (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 037905bea9..0c0762ad8e 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -32,6 +32,7 @@ require 'active_support/core_ext' require 'active_support/clean_logger' require 'active_support/dependencies' require 'active_support/reloadable' +require 'active_support/deprecation' require 'active_support/ordered_options' require 'active_support/option_merger' 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) -- cgit v1.2.3