diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-24 04:11:27 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-24 04:11:27 +0000 |
commit | 7309f9cc007f1cc05eb70967356069161d867356 (patch) | |
tree | 6dcfc346ff9055c7d938b8f01be917c6ed1edd98 /ext | |
parent | 655b2ade4984f8d0ad6c76d6eff35262ad7d2619 (diff) |
* ext/psych/lib/psych.rb: supporting deprecated syck method
add_ruby_type
* ext/psych/lib/psych/visitors/to_ruby.rb: ditto
* test/psych/test_deprecated.rb: ditto
* test/psych/test_psych.rb: ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/psych/lib/psych.rb | 15 | ||||
-rw-r--r-- | ext/psych/lib/psych/visitors/to_ruby.rb | 10 |
2 files changed, 19 insertions, 6 deletions
diff --git a/ext/psych/lib/psych.rb b/ext/psych/lib/psych.rb index 58c77f40fd..16602ef221 100644 --- a/ext/psych/lib/psych.rb +++ b/ext/psych/lib/psych.rb @@ -207,11 +207,22 @@ module Psych # :stopdoc: @domain_types = {} def self.add_domain_type domain, type_tag, &block - @domain_types[type_tag] = ["http://#{domain}", block] + key = ['tag', domain, type_tag].join ':' + @domain_types[key] = [key, block] + @domain_types["tag:#{type_tag}"] = [key, block] end def self.add_builtin_type type_tag, &block - @domain_types[type_tag] = ['yaml.org', block] + domain = 'yaml.org,2002' + key = ['tag', domain, type_tag].join ':' + @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 diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb index 56c970002c..bbbe9a8366 100644 --- a/ext/psych/lib/psych/visitors/to_ruby.rb +++ b/ext/psych/lib/psych/visitors/to_ruby.rb @@ -16,10 +16,12 @@ module Psych result = super return result if @domain_types.empty? || !target.tag - short_name = target.tag.sub(/^!/, '').split('/', 2).last - if Psych.domain_types.key? short_name - url, block = Psych.domain_types[short_name] - return block.call "#{url}:#{short_name}", result + key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:') + key = "tag:#{key}" unless key.start_with?('tag:') + + if @domain_types.key? key + value, block = @domain_types[key] + return block.call value, result end result |