mirror of
https://github.com/github/rails.git
synced 2026-01-28 15:58:03 -05:00
Introduce Dependencies.warnings_on_first_load setting. If true, enables warnings on first load of a require_dependency. Otherwise, loads without warnings. Disabled (set to false) by default.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3190 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Introduce Dependencies.warnings_on_first_load setting. If true, enables warnings on first load of a require_dependency. Otherwise, loads without warnings. Disabled (set to false) by default. [Jeremy Kemper]
|
||||
|
||||
* Active Support is warnings-safe. #1792 [Eric Hodel]
|
||||
|
||||
* Introduce enable_warnings counterpart to silence_warnings. Turn warnings on when loading a file for the first time if Dependencies.mechanism == :load. Common mistakes such as redefined methods will print warnings to stderr. [Jeremy Kemper]
|
||||
|
||||
@@ -6,6 +6,10 @@ require File.dirname(__FILE__) + '/core_ext/kernel'
|
||||
module Dependencies #:nodoc:
|
||||
extend self
|
||||
|
||||
# Should we turn on Ruby warnings on the first load of dependent files?
|
||||
mattr_accessor :warnings_on_first_load
|
||||
self.warnings_on_first_load = false
|
||||
|
||||
# All files ever loaded.
|
||||
mattr_accessor :history
|
||||
self.history = Set.new
|
||||
@@ -50,8 +54,9 @@ module Dependencies #:nodoc:
|
||||
loaded << file_name
|
||||
|
||||
begin
|
||||
# Enable warnings iff this file has not been loaded before.
|
||||
if history.include?(file_name)
|
||||
# Enable warnings iff this file has not been loaded before and
|
||||
# warnings_on_first_load is set.
|
||||
if !warnings_on_first_load or history.include?(file_name)
|
||||
load load_file_name
|
||||
else
|
||||
enable_warnings { load load_file_name }
|
||||
|
||||
@@ -46,6 +46,7 @@ class DependenciesTest < Test::Unit::TestCase
|
||||
|
||||
def test_warnings_should_be_enabled_on_first_load
|
||||
old_mechanism, Dependencies.mechanism = Dependencies.mechanism, :load
|
||||
old_warnings, Dependencies.warnings_on_first_load = Dependencies.warnings_on_first_load, true
|
||||
|
||||
filename = "#{File.dirname(__FILE__)}/dependencies/check_warnings"
|
||||
$check_warnings_load_count = 0
|
||||
@@ -78,6 +79,7 @@ class DependenciesTest < Test::Unit::TestCase
|
||||
assert Dependencies.loaded.include?(filename)
|
||||
ensure
|
||||
Dependencies.mechanism = old_mechanism
|
||||
Dependencies.warnings_on_first_load = old_warnings
|
||||
end
|
||||
|
||||
def test_mutual_dependencies_dont_infinite_loop
|
||||
|
||||
Reference in New Issue
Block a user