Permalink
Browse files

require_dependency should allow Pathname-like objects, not just String

  • Loading branch information...
bf4 committed Sep 30, 2013
1 parent 432ffdb commit 0b0beb71d648efb417207502e142289ee77aa723
Showing with 14 additions and 1 deletion.
  1. +3 −1 activesupport/lib/active_support/dependencies.rb
  2. +11 −0 activesupport/test/dependencies_test.rb
@@ -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)
@@ -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'

0 comments on commit 0b0beb7

Please sign in to comment.