diff options
-rw-r--r-- | lib/psych.rb | 8 | ||||
-rw-r--r-- | lib/psych/deprecated.rb | 20 | ||||
-rw-r--r-- | lib/psych/visitors/to_ruby.rb | 2 | ||||
-rw-r--r-- | test/psych/test_deprecated.rb | 18 |
4 files changed, 39 insertions, 9 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index 16602ef..59f9712 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -218,13 +218,6 @@ module Psych @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 @@ -241,6 +234,5 @@ module Psych attr_accessor :dump_tags attr_accessor :domain_types end - # :startdoc: end diff --git a/lib/psych/deprecated.rb b/lib/psych/deprecated.rb index 093f145..b306b85 100644 --- a/lib/psych/deprecated.rb +++ b/lib/psych/deprecated.rb @@ -30,6 +30,26 @@ module Psych list.each(&block) end + def self.detect_implicit thing + warn "#{caller[0]}: detect_implicit is deprecated" if $VERBOSE + return '' unless String === thing + 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 diff --git a/lib/psych/visitors/to_ruby.rb b/lib/psych/visitors/to_ruby.rb index bbbe9a8..e28ac7b 100644 --- a/lib/psych/visitors/to_ruby.rb +++ b/lib/psych/visitors/to_ruby.rb @@ -17,7 +17,7 @@ module Psych 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] diff --git a/test/psych/test_deprecated.rb b/test/psych/test_deprecated.rb index c93b36e..c2c8a97 100644 --- a/test/psych/test_deprecated.rb +++ b/test/psych/test_deprecated.rb @@ -163,5 +163,23 @@ module Psych assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types end + + def test_detect_implicit + assert_equal '', Psych.detect_implicit(nil) + assert_equal '', Psych.detect_implicit(Object.new) + assert_equal '', Psych.detect_implicit(1.2) + 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 |