mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/psych/lib/psych/visitors/yaml_tree.rb: Rescue exceptions when
people implement the method method. Thanks Lin Jen-Shin. [ruby-core:35255] * test/psych/visitors/test_yaml_tree.rb: test for implementation of method method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
095b279464
commit
4df71924e4
3 changed files with 37 additions and 12 deletions
|
|
@ -1,3 +1,12 @@
|
||||||
|
Wed Mar 9 12:50:24 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: Rescue exceptions when
|
||||||
|
people implement the method method. Thanks Lin Jen-Shin.
|
||||||
|
[ruby-core:35255]
|
||||||
|
|
||||||
|
* test/psych/visitors/test_yaml_tree.rb: test for implementation of
|
||||||
|
method method.
|
||||||
|
|
||||||
Wed Mar 9 11:53:31 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
Wed Mar 9 11:53:31 2011 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* enc/shift_jis.c: Change SJIS as an alias of Windows-31J.
|
* enc/shift_jis.c: Change SJIS as an alias of Windows-31J.
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,20 @@ module Psych
|
||||||
end
|
end
|
||||||
|
|
||||||
if target.respond_to?(:to_yaml)
|
if target.respond_to?(:to_yaml)
|
||||||
loc = target.method(:to_yaml).source_location.first
|
begin
|
||||||
if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/
|
loc = target.method(:to_yaml).source_location.first
|
||||||
unless target.respond_to?(:encode_with)
|
if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/
|
||||||
if $VERBOSE
|
unless target.respond_to?(:encode_with)
|
||||||
warn "implementing to_yaml is deprecated, please implement \"encode_with\""
|
if $VERBOSE
|
||||||
end
|
warn "implementing to_yaml is deprecated, please implement \"encode_with\""
|
||||||
|
end
|
||||||
|
|
||||||
target.to_yaml(:nodump => true)
|
target.to_yaml(:nodump => true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
# public_method or source_location might be overridden,
|
||||||
|
# and it's OK to skip it since it's only to emit a warning
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -300,12 +305,17 @@ module Psych
|
||||||
|
|
||||||
# FIXME: remove this method once "to_yaml_properties" is removed
|
# FIXME: remove this method once "to_yaml_properties" is removed
|
||||||
def find_ivars target
|
def find_ivars target
|
||||||
loc = target.method(:to_yaml_properties).source_location.first
|
begin
|
||||||
unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb')
|
loc = target.method(:to_yaml_properties).source_location.first
|
||||||
if $VERBOSE
|
unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb')
|
||||||
warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\""
|
if $VERBOSE
|
||||||
|
warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\""
|
||||||
|
end
|
||||||
|
return target.to_yaml_properties
|
||||||
end
|
end
|
||||||
return target.to_yaml_properties
|
rescue
|
||||||
|
# public_method or source_location might be overridden,
|
||||||
|
# and it's OK to skip it since it's only to emit a warning.
|
||||||
end
|
end
|
||||||
|
|
||||||
target.instance_variables
|
target.instance_variables
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ module Psych
|
||||||
assert_equal s.foo, obj.foo
|
assert_equal s.foo, obj.foo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_override_method
|
||||||
|
s = Struct.new(:method).new('override')
|
||||||
|
obj = Psych.load(Psych.dump(s))
|
||||||
|
assert_equal s.method, obj.method
|
||||||
|
end
|
||||||
|
|
||||||
def test_exception
|
def test_exception
|
||||||
ex = Exception.new 'foo'
|
ex = Exception.new 'foo'
|
||||||
loaded = Psych.load(Psych.dump(ex))
|
loaded = Psych.load(Psych.dump(ex))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue