From edc7c521b8692dbbf08a6ec625d0937d6c459e65 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 21 Nov 2005 07:06:33 +0000 Subject: [PATCH] Turn warnings on when loading a file if Dependencies.mechanism == :load. Common mistakes such as redefined methods will print warnings to stderr. References #752. References #1792. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3124 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/dependencies.rb | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index ac4076d715..1708723f8c 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Turn warnings on when loading a file if Dependencies.mechanism == :load. Common mistakes such as redefined methods will print warnings to stderr. [Jeremy Kemper] + * Add Symbol#to_proc, which allows for, e.g. [:foo, :bar].map(&:to_s). [Marcel Molina Jr.] * Added the following methods [Marcel Molina Jr., Sam Stephenson]: diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 9681af6dff..30911453bc 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -33,12 +33,21 @@ def associate_with(file_name) def clear self.loaded = [ ] end - + def require_or_load(file_name) file_name = "#{file_name}.rb" unless ! load? || file_name[-3..-1] == '.rb' - load? ? load(file_name) : require(file_name) + if load? + begin + original_verbosity, $VERBOSE = $VERBOSE, true + load file_name + ensure + $VERBOSE = original_verbosity + end + else + require file_name + end end - + def remove_subclasses_for(*classes) Object.remove_subclasses_of(*classes) end