1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27480 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2010-04-24 20:35:20 +00:00
parent d69c502c9f
commit 2d9c054412
4 changed files with 25 additions and 8 deletions

View file

@ -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

View file

@ -36,6 +36,20 @@ module Psych
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

View file

@ -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]

View file

@ -171,5 +171,15 @@ module Psych
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