ruby-changes:15388
From: tenderlove <ko1@a...>
Date: Sat, 10 Apr 2010 05:33:39 +0900 (JST)
Subject: [ruby-changes:15388] Ruby:r27280 (trunk): * ext/psych/lib/psych/deprecated.rb: implementing Psych.quick_emit and
tenderlove 2010-04-10 05:33:21 +0900 (Sat, 10 Apr 2010) New Revision: 27280 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27280 Log: * ext/psych/lib/psych/deprecated.rb: implementing Psych.quick_emit and adding deprecation warnings. * ext/psych/lib/psych/visitors/to_ruby.rb: supporting deprecated yaml_initialize api. * ext/psych/lib/psych/visitors/yaml_tree.rb: supporting deprecated to_yaml api. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/to_ruby.rb trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/ext/psych/lib/psych.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27279) +++ ChangeLog (revision 27280) @@ -1,3 +1,12 @@ +Sat Apr 10 05:27:26 2010 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/deprecated.rb: implementing Psych.quick_emit and + adding deprecation warnings. + * ext/psych/lib/psych/visitors/to_ruby.rb: supporting deprecated + yaml_initialize api. + * ext/psych/lib/psych/visitors/yaml_tree.rb: supporting deprecated + to_yaml api. + Sat Apr 10 01:08:53 2010 Aaron Patterson <aaron@t...> * ext/psych/parser.c: parse raises a TypeError when nil is passed in. Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 27279) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 27280) @@ -36,6 +36,19 @@ return append Nodes::Alias.new target.object_id.to_s end + if target.respond_to?(:to_yaml) + loc = target.method(:to_yaml).source_location.first + if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/ + unless target.respond_to?(:encode_with) + if $VERBOSE + warn "implementing to_yaml is deprecated, please implement \"encode_with\"" + end + + target.to_yaml(:nodump => true) + end + end + end + if target.respond_to?(:encode_with) dump_coder target else Index: ext/psych/lib/psych/visitors/to_ruby.rb =================================================================== --- ext/psych/lib/psych/visitors/to_ruby.rb (revision 27279) +++ ext/psych/lib/psych/visitors/to_ruby.rb (revision 27280) @@ -219,10 +219,16 @@ end def init_with o, h, node + c = Psych::Coder.new(node.tag) + c.map = h + if o.respond_to?(:init_with) - c = Psych::Coder.new(node.tag) - c.map = h o.init_with c + elsif o.respond_to?(:yaml_initialize) + if $VERBOSE + "Implementing #{o.class}#yaml_initialize is deprecated, please implement \"init_with(coder)\"" + end + o.yaml_initialize c.tag, c.map else h.each { |k,v| o.instance_variable_set(:"@#{k}", v) } end Index: ext/psych/lib/psych.rb =================================================================== --- ext/psych/lib/psych.rb (revision 27279) +++ ext/psych/lib/psych.rb (revision 27280) @@ -8,6 +8,7 @@ require 'psych/set' require 'psych/coder' require 'psych/core_ext' +require 'psych/deprecated' ### # = Overview -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/