Skip to content

Commit

Permalink
Merge pull request rails#12412 from bf4/allow_pathname_for_require_de…
Browse files Browse the repository at this point in the history
…pendency

Allow Pathname for require dependency
  • Loading branch information
fxn committed Oct 1, 2013
2 parents 78fcc5f + 0b0beb7 commit 2254615
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion activesupport/lib/active_support/dependencies.rb
Expand Up @@ -198,9 +198,11 @@ def require_or_load(file_name)
Dependencies.require_or_load(file_name)
end

# Files required this way can be reloaded in development mode
def require_dependency(file_name, message = "No such file to load -- %s")
file_name = file_name.to_path if file_name.respond_to?(:to_path)
unless file_name.is_a?(String)
raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}"
raise ArgumentError, "the file name must either be a String or implement #to_path -- you passed #{file_name.inspect}"
end

Dependencies.depend_on(file_name, message)
Expand Down
11 changes: 11 additions & 0 deletions activesupport/test/dependencies_test.rb
Expand Up @@ -35,6 +35,17 @@ def test_depend_on_path
assert_equal expected.path, e.path
end

def test_require_dependency_accepts_an_object_which_implements_to_path
o = Object.new
def o.to_path; 'dependencies/service_one'; end
assert_nothing_raised {
require_dependency o
}
assert defined?(ServiceOne)
ensure
remove_constants(:ServiceOne)
end

def test_tracking_loaded_files
require_dependency 'dependencies/service_one'
require_dependency 'dependencies/service_two'
Expand Down

0 comments on commit 2254615

Please sign in to comment.