未验证 提交 feea0811 编写于 作者: R Rafael Mendonça França

Merge pull request #28006 from fareastside/master

Allow ActiveSupport::MarshalWithAutoloading#load to take a Proc
* In Core Extensions, make `MarshalWithAutoloading#load` pass through the second, optional
argument for `Marshal#load( source [, proc] )`. This way we don't have to do
`Marshal.method(:load).super_method.call(sourse, proc)` just to be able to pass a proc.
*Jeff Latz*
* `ActiveSupport::Gzip.decompress` now checks checksum and length in footer.
*Dylan Thacker-Smith*
......
module ActiveSupport
module MarshalWithAutoloading # :nodoc:
def load(source)
super(source)
def load(source, proc = nil)
super(source, proc)
rescue ArgumentError, NameError => exc
if exc.message.match(%r|undefined class/module (.+?)(?:::)?\z|)
# try loading the class/module
......
......@@ -19,6 +19,19 @@ def teardown
end
end
test "that Marshal#load still works when passed a proc" do
example_string = "test"
example_proc = Proc.new do |o|
if o.is_a?(String)
o.capitalize!
end
end
dumped = Marshal.dump(example_string)
assert_equal Marshal.load(dumped, example_proc), "Test"
end
test "that a missing class is autoloaded from string" do
dumped = nil
with_autoloading_fixtures do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册