mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
dependencies.rb: keep the decorated #load and #require private [closes #17553]
This commit is contained in:
parent
1906758210
commit
0ed6ebcf90
3 changed files with 36 additions and 13 deletions
|
@ -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*
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue