ruby-changes:15466
From: tenderlove <ko1@a...>
Date: Sat, 17 Apr 2010 05:34:58 +0900 (JST)
Subject: [ruby-changes:15466] Ruby:r27365 (trunk): * ext/psych/lib/psych/core_ext.rb (yaml_as): supporting deprecated
tenderlove 2010-04-17 05:31:59 +0900 (Sat, 17 Apr 2010) New Revision: 27365 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27365 Log: * ext/psych/lib/psych/core_ext.rb (yaml_as): supporting deprecated "yaml_as" method * ext/syck/lib/syck/tag.rb: ditto Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/core_ext.rb trunk/ext/syck/lib/syck/tag.rb trunk/test/psych/test_deprecated.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27364) +++ ChangeLog (revision 27365) @@ -1,3 +1,9 @@ +Sat Apr 17 05:30:22 2010 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/core_ext.rb (yaml_as): supporting deprecated + "yaml_as" method + * ext/syck/lib/syck/tag.rb: ditto + Sat Apr 17 05:25:15 2010 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/coder.rb (scalar): supporting deprecated methods Index: ext/psych/lib/psych/core_ext.rb =================================================================== --- ext/psych/lib/psych/core_ext.rb (revision 27364) +++ ext/psych/lib/psych/core_ext.rb (revision 27365) @@ -16,6 +16,19 @@ alias :to_yaml :psych_to_yaml end +class Module + def psych_yaml_as url + return if caller[0].end_with?('rubytypes.rb') + if $VERBOSE + warn "#{caller[0]}: yaml_as is deprecated, please use yaml_tag" + end + Psych.add_tag(url, self) + end + + remove_method :yaml_as rescue nil + alias :yaml_as :psych_yaml_as +end + module Kernel def psych_y *objects puts Psych.dump_stream(*objects) Index: ext/syck/lib/syck/tag.rb =================================================================== --- ext/syck/lib/syck/tag.rb (revision 27364) +++ ext/syck/lib/syck/tag.rb (revision 27365) @@ -56,7 +56,7 @@ # Adds a taguri _tag_ to a class, used when dumping or loading the class # in YAML. See YAML::tag_class for detailed information on typing and # taguris. - def yaml_as( tag, sc = true ) + def syck_yaml_as( tag, sc = true ) verbose, $VERBOSE = $VERBOSE, nil class_eval <<-"END", __FILE__, __LINE__+1 attr_writer :taguri @@ -78,6 +78,9 @@ ensure $VERBOSE = verbose end + remove_method :yaml_as rescue nil + alias :yaml_as :syck_yaml_as + # Transforms the subclass name into a name suitable for display # in a subclassed tag. def yaml_tag_class_name Index: test/psych/test_deprecated.rb =================================================================== --- test/psych/test_deprecated.rb (revision 27364) +++ test/psych/test_deprecated.rb (revision 27365) @@ -139,5 +139,13 @@ assert_equal 'some string', coder.scalar assert_equal :scalar, coder.type end + + class YamlAs + yaml_as 'helloworld' + end + + def test_yaml_as + assert_match(/helloworld/, Psych.dump(YamlAs.new)) + end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/