Skip to content

Commit

Permalink
Update require_dependency to return true or false as require does.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4778 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
seckar committed Aug 16, 2006
1 parent 50be89b commit 38f598e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions activesupport/lib/active_support/dependencies.rb
Expand Up @@ -75,21 +75,22 @@ def require_or_load(file_name, const_path = nil)
load_args << const_path unless const_path.nil?

if !warnings_on_first_load or history.include?(expanded)
load_file(*load_args)
result = load_file(*load_args)
else
enable_warnings { load_file(*load_args) }
enable_warnings { result = load_file(*load_args) }
end
rescue
loaded.delete expanded
raise
end
else
log "requiring #{file_name}"
require file_name
result = require file_name
end

# Record history *after* loading so first load gets warnings.
history << expanded
return result
end

# Is the provided constant path defined?
Expand Down Expand Up @@ -157,12 +158,13 @@ def load_file(path, const_paths = autoloadable_constants_for_path(path))
const_paths = [const_paths].compact unless const_paths.is_a? Array
undefined_before = const_paths.reject(&method(:qualified_const_defined?))

load path
result = load path

newly_defined_paths = const_paths.select(&method(:qualified_const_defined?))
autoloaded_constants.concat newly_defined_paths
autoloaded_constants.uniq!
log "loading #{path} defined #{newly_defined_paths * ', '}" unless newly_defined_paths.empty?
return result
end

# Return the constant path for the provided parent and constant name.
Expand Down
6 changes: 3 additions & 3 deletions activesupport/test/dependencies_test.rb
Expand Up @@ -61,11 +61,11 @@ def test_dependency_which_raises_exception_isnt_added_to_loaded_set
end

def test_warnings_should_be_enabled_on_first_load
with_loading do
with_loading 'dependencies' do
old_warnings, Dependencies.warnings_on_first_load = Dependencies.warnings_on_first_load, true

filename = "#{File.dirname(__FILE__)}/dependencies/check_warnings"
expanded = File.expand_path(filename)
filename = "check_warnings"
expanded = File.expand_path("test/dependencies/#{filename}")
$check_warnings_load_count = 0

assert !Dependencies.loaded.include?(expanded)
Expand Down

0 comments on commit 38f598e

Please sign in to comment.