From 0b7067d8497c4d832b32233888ce973ab4357e5d Mon Sep 17 00:00:00 2001 From: Nikita Afanasenko Date: Mon, 29 Oct 2012 19:22:59 +0400 Subject: Provide a call stack for deprecation warnings where needed. It's sometimes hard to quickly find where deprecated call was performed, especially in case of migrating between Rails versions. So this is an attempt to improve the call stack part of the warning message by providing caller explicitly. --- activesupport/lib/active_support/benchmarkable.rb | 3 ++- activesupport/lib/active_support/callbacks.rb | 7 +++++-- activesupport/lib/active_support/json/variable.rb | 5 +++-- activesupport/lib/active_support/test_case.rb | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/benchmarkable.rb b/activesupport/lib/active_support/benchmarkable.rb index 3d8bb13c49..4c7a694c52 100644 --- a/activesupport/lib/active_support/benchmarkable.rb +++ b/activesupport/lib/active_support/benchmarkable.rb @@ -48,7 +48,8 @@ module ActiveSupport # Silence the logger during the execution of the block. def silence - ActiveSupport::Deprecation.warn "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1." + message = "ActiveSupport::Benchmarkable#silence is deprecated. It will be removed from Rails 4.1." + ActiveSupport::Deprecation.warn(message, caller) old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger yield ensure diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index a02793bde9..a4ea6748f9 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -282,12 +282,15 @@ module ActiveSupport def _normalize_legacy_filter(kind, filter) if !filter.respond_to?(kind) && filter.respond_to?(:filter) - ActiveSupport::Deprecation.warn("Filter object with #filter method is deprecated. Define method corresponding to filter type (#before, #after or #around).") + message = "Filter object with #filter method is deprecated. Define method corresponding " \ + "to filter type (#before, #after or #around)." + ActiveSupport::Deprecation.warn(message, caller) filter.singleton_class.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{kind}(context, &block) filter(context, &block) end RUBY_EVAL elsif filter.respond_to?(:before) && filter.respond_to?(:after) && kind == :around && !filter.respond_to?(:around) - ActiveSupport::Deprecation.warn("Filter object with #before and #after methods is deprecated. Define #around method instead.") + message = "Filter object with #before and #after methods is deprecated. Define #around method instead." + ActiveSupport::Deprecation.warn(message, caller) def filter.around(context) should_continue = before(context) yield if should_continue diff --git a/activesupport/lib/active_support/json/variable.rb b/activesupport/lib/active_support/json/variable.rb index 8af661a795..42e25fbdb3 100644 --- a/activesupport/lib/active_support/json/variable.rb +++ b/activesupport/lib/active_support/json/variable.rb @@ -5,8 +5,9 @@ module ActiveSupport # Deprecated: A string that returns itself as its JSON-encoded form. class Variable < String def initialize(*args) - ActiveSupport::Deprecation.warn 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.1. ' \ - 'For your own custom JSON literals, define #as_json and #encode_json yourself.' + message = 'ActiveSupport::JSON::Variable is deprecated and will be removed in Rails 4.1. ' \ + 'For your own custom JSON literals, define #as_json and #encode_json yourself.' + ActiveSupport::Deprecation.warn(message, caller) super end diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 81d97ecb40..646e70c29f 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -43,7 +43,8 @@ module ActiveSupport if block_given? super else - ActiveSupport::Deprecation.warn("`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n") + message = "`describe` without a block is deprecated, please switch to: `def self.name; #{text.inspect}; end`\n" + ActiveSupport::Deprecation.warn(message, caller) class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def self.name -- cgit v1.2.3