aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2014-11-10 14:17:01 -0800
committerXavier Noria <fxn@hashref.com>2014-11-10 14:29:29 -0800
commit0ed6ebcf9095c65330d3950cfb6b75ba7ea78853 (patch)
treececf2d28bedbbe45d36b224a751c75b0867ad7d1 /activesupport
parent19067582104e8fc0e98a977f5f0e6a4cd06d8c1a (diff)
downloadrails-0ed6ebcf9095c65330d3950cfb6b75ba7ea78853.tar.gz
rails-0ed6ebcf9095c65330d3950cfb6b75ba7ea78853.tar.bz2
rails-0ed6ebcf9095c65330d3950cfb6b75ba7ea78853.zip
dependencies.rb: keep the decorated #load and #require private [closes #17553]
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md6
-rw-r--r--activesupport/lib/active_support/dependencies.rb31
-rw-r--r--activesupport/test/dependencies_test.rb12
3 files changed, 36 insertions, 13 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 468b990f39..ed30c7de70 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,9 @@
+* The decorated `load` and `require` methods are now kept private.
+
+ Fixes #17553.
+
+ *Xavier Noria*
+
* `String#remove` and `String#remove!` accept multiple arguments.
*Pavel Pravosud*
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index a89c769e34..65a370dd30 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -205,7 +205,10 @@ module ActiveSupport #:nodoc:
# Object includes this module.
module Loadable #:nodoc:
def self.exclude_from(base)
- base.class_eval { define_method(:load, Kernel.instance_method(:load)) }
+ base.class_eval do
+ define_method(:load, Kernel.instance_method(:load))
+ private :load
+ end
end
def require_or_load(file_name)
@@ -241,18 +244,6 @@ module ActiveSupport #:nodoc:
raise
end
- def load(file, wrap = false)
- result = false
- load_dependency(file) { result = super }
- result
- end
-
- def require(file)
- result = false
- load_dependency(file) { result = super }
- result
- end
-
# Mark the given constant as unloadable. Unloadable constants are removed
# each time dependencies are cleared.
#
@@ -269,6 +260,20 @@ module ActiveSupport #:nodoc:
def unloadable(const_desc)
Dependencies.mark_for_unload const_desc
end
+
+ private
+
+ def load(file, wrap = false)
+ result = false
+ load_dependency(file) { result = super }
+ result
+ end
+
+ def require(file)
+ result = false
+ load_dependency(file) { result = super }
+ result
+ end
end
# Exception file-blaming.
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index 67e31fc1e1..96e9bd1e65 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -1037,6 +1037,18 @@ class DependenciesTest < ActiveSupport::TestCase
assert_nothing_raised { ActiveSupport::Dependencies.hook! }
end
+ def test_load_and_require_stay_private
+ assert Object.private_methods.include?(:load)
+ assert Object.private_methods.include?(:require)
+
+ ActiveSupport::Dependencies.unhook!
+
+ assert Object.private_methods.include?(:load)
+ assert Object.private_methods.include?(:require)
+ ensure
+ ActiveSupport::Dependencies.hook!
+ end
+
def test_unhook
ActiveSupport::Dependencies.unhook!
assert !Module.new.respond_to?(:const_missing_without_dependencies)