Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add silencing to deprecations; avoid self-scolding.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4760 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 30fa7053be89de6a4615788862e052be925342c2 1 parent 2ac4839
Nicholas Seckar seckar authored
2  activesupport/CHANGELOG
View
@@ -1,5 +1,7 @@
*SVN*
+* Add Deprecation.silence so that Reloadable does not scold itself. [Nicholas Seckar]
+
* Add debugging logging to Dependencies. Currently can be enabled with Dependencies.log_activity = true; adding to Initializer and documenting is forthcoming. [Nicholas Seckar]
* Replace Reloadable with improvements to the Dependencies mechanism. [Nicholas Seckar]
16 activesupport/lib/active_support/deprecation.rb
View
@@ -9,13 +9,27 @@ module Deprecation
class << self
def warn(message = nil, callstack = caller)
- behavior.call(deprecation_message(callstack, message)) if behavior
+ behavior.call(deprecation_message(callstack, message)) if behavior && ! silenced?
end
def default_behavior
DEFAULT_BEHAVIORS[RAILS_ENV.to_s] if defined?(RAILS_ENV)
end
+ # Have deprecations been silenced?
+ def silenced?
+ @silenced
+ end
+
+ # Silence deprecations for the duration of the provided block. For internal
+ # use only.
+ def silence
+ old_silenced, @silenced = @silenced, true # We could have done behavior = nil...
+ yield
+ ensure
+ @silenced = old_silenced
+ end
+
private
def deprecation_message(callstack, message = nil)
file, line, method = extract_callstack(callstack)
7 activesupport/lib/active_support/reloadable.rb
View
@@ -25,10 +25,11 @@ class << base
end
def reloadable_classes
- included_in_classes.select { |klass| klass.reloadable? }
+ ActiveSupport::Deprecation.silence do
+ included_in_classes.select { |klass| klass.reloadable? }
+ end
end
- # Commented out so dispatcher doesn't warn. Should we just disable Reloadable?
- # deprecate :reloadable_classes
+ deprecate :reloadable_classes
end
# Captures the common pattern where a base class should not be reloaded,
6 activesupport/test/deprecation_test.rb
View
@@ -78,4 +78,10 @@ def test_assert_deprecation_without_match
end
end
+ def test_silence
+ ActiveSupport::Deprecation.silence do
+ assert_not_deprecated { @dtc.partially }
+ end
+ end
+
end
2  railties/CHANGELOG
View
@@ -1,5 +1,7 @@
*SVN*
+* Don't warn dispatcher of Reloadable deprecations. [Nicholas Seckar]
+
* Rearrange application resetting and preparation, fix bug with leaking subclasses hash in ActiveRecord::Base [Rick Olson]
ActiveRecord::Base.reset_subclasses is called before Dependencies are cleared and classes removed.
4 railties/lib/dispatcher.rb
View
@@ -56,7 +56,9 @@ def dispatch(cgi = nil, session_options = ActionController::CgiRequest::DEFAULT_
def reset_application!
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
Dependencies.clear
- Class.remove_class(*Reloadable.reloadable_classes)
+ ActiveSupport::Deprecation.silence do # TODO: Remove after 1.2
+ Class.remove_class(*Reloadable.reloadable_classes)
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.