summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/psych/lib/psych.rb15
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb10
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