[前][次][番号順一覧][スレッド一覧]

ruby-changes:15574

From: tenderlove <ko1@a...>
Date: Sun, 25 Apr 2010 05:39:17 +0900 (JST)
Subject: [ruby-changes:15574] Ruby:r27480 (trunk): * ext/psych/lib/psych/deprecated.rb: adding support for deprecated

tenderlove	2010-04-25 05:35:20 +0900 (Sun, 25 Apr 2010)

  New Revision: 27480

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27480

  Log:
    * ext/psych/lib/psych/deprecated.rb: adding support for deprecated
      "add_private_type" function
    * ext/psych/lib/psych.rb: ditto
    * ext/psych/lib/psych/visitors/to_ruby.rb: ditto
    * test/psych/test_deprecated.rb: ditto

  Modified files:
    trunk/ext/psych/lib/psych/deprecated.rb
    trunk/ext/psych/lib/psych/visitors/to_ruby.rb
    trunk/ext/psych/lib/psych.rb
    trunk/test/psych/test_deprecated.rb

Index: ext/psych/lib/psych/deprecated.rb
===================================================================
--- ext/psych/lib/psych/deprecated.rb	(revision 27479)
+++ ext/psych/lib/psych/deprecated.rb	(revision 27480)
@@ -36,6 +36,20 @@
     return 'null' if '' == thing
     ScalarScanner.new.tokenize(thing).class.name.downcase
   end
+
+  def self.add_ruby_type type_tag, &block
+    warn "#{caller[0]}: add_ruby_type is deprecated, use add_domain_type" if $VERBOSE
+    domain = 'ruby.yaml.org,2002'
+    key = ['tag', domain, type_tag].join ':'
+    @domain_types[key] = [key, block]
+  end
+
+  def self.add_private_type type_tag, &block
+    warn "#{caller[0]}: add_private_type is deprecated, use add_domain_type" if $VERBOSE
+    domain = 'x-private'
+    key = [domain, type_tag].join ':'
+    @domain_types[key] = [key, block]
+  end
 end
 
 class Object
Index: ext/psych/lib/psych/visitors/to_ruby.rb
===================================================================
--- ext/psych/lib/psych/visitors/to_ruby.rb	(revision 27479)
+++ ext/psych/lib/psych/visitors/to_ruby.rb	(revision 27480)
@@ -17,7 +17,7 @@
         return result if @domain_types.empty? || !target.tag
 
         key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
-        key = "tag:#{key}" unless key.start_with?('tag:')
+        key = "tag:#{key}" unless key =~ /^(tag:|x-private)/
 
         if @domain_types.key? key
           value, block = @domain_types[key]
Index: ext/psych/lib/psych.rb
===================================================================
--- ext/psych/lib/psych.rb	(revision 27479)
+++ ext/psych/lib/psych.rb	(revision 27480)
@@ -218,13 +218,6 @@
     @domain_types[key] = [key, block]
   end
 
-  def self.add_ruby_type type_tag, &block
-    warn "#{caller[0]}: add_ruby_type is deprecated, use add_domain_type" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
-    domain = 'ruby.yaml.org,2002'
-    key = ['tag', domain, type_tag].join ':'
-    @domain_types[key] = [key, block]
-  end
-
   def self.remove_type type_tag
     @domain_types.delete type_tag
   end
Index: test/psych/test_deprecated.rb
===================================================================
--- test/psych/test_deprecated.rb	(revision 27479)
+++ test/psych/test_deprecated.rb	(revision 27480)
@@ -171,5 +171,15 @@
       assert_equal 'null', Psych.detect_implicit('')
       assert_equal 'string', Psych.detect_implicit('foo')
     end
+
+    def test_private_type
+      types = []
+      Psych.add_private_type('foo') { |*args| types << args }
+      Psych.load <<-eoyml
+- !x-private:foo bar
+      eoyml
+
+      assert_equal [["x-private:foo", "bar"]], types
+    end
   end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]