зеркало из https://github.com/github/ruby.git
* ext/psych/lib/psych/core_ext.rb (yaml_as): supporting deprecated
"yaml_as" method * ext/syck/lib/syck/tag.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
2db7b7f3fe
Коммит
5b5bbdbb35
|
@ -1,3 +1,9 @@
|
||||||
|
Sat Apr 17 05:30:22 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* ext/psych/lib/psych/core_ext.rb (yaml_as): supporting deprecated
|
||||||
|
"yaml_as" method
|
||||||
|
* ext/syck/lib/syck/tag.rb: ditto
|
||||||
|
|
||||||
Sat Apr 17 05:25:15 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
Sat Apr 17 05:25:15 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/lib/psych/coder.rb (scalar): supporting deprecated methods
|
* ext/psych/lib/psych/coder.rb (scalar): supporting deprecated methods
|
||||||
|
|
|
@ -16,6 +16,19 @@ class Object
|
||||||
alias :to_yaml :psych_to_yaml
|
alias :to_yaml :psych_to_yaml
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Module
|
||||||
|
def psych_yaml_as url
|
||||||
|
return if caller[0].end_with?('rubytypes.rb')
|
||||||
|
if $VERBOSE
|
||||||
|
warn "#{caller[0]}: yaml_as is deprecated, please use yaml_tag"
|
||||||
|
end
|
||||||
|
Psych.add_tag(url, self)
|
||||||
|
end
|
||||||
|
|
||||||
|
remove_method :yaml_as rescue nil
|
||||||
|
alias :yaml_as :psych_yaml_as
|
||||||
|
end
|
||||||
|
|
||||||
module Kernel
|
module Kernel
|
||||||
def psych_y *objects
|
def psych_y *objects
|
||||||
puts Psych.dump_stream(*objects)
|
puts Psych.dump_stream(*objects)
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Module
|
||||||
# Adds a taguri _tag_ to a class, used when dumping or loading the class
|
# Adds a taguri _tag_ to a class, used when dumping or loading the class
|
||||||
# in YAML. See YAML::tag_class for detailed information on typing and
|
# in YAML. See YAML::tag_class for detailed information on typing and
|
||||||
# taguris.
|
# taguris.
|
||||||
def yaml_as( tag, sc = true )
|
def syck_yaml_as( tag, sc = true )
|
||||||
verbose, $VERBOSE = $VERBOSE, nil
|
verbose, $VERBOSE = $VERBOSE, nil
|
||||||
class_eval <<-"END", __FILE__, __LINE__+1
|
class_eval <<-"END", __FILE__, __LINE__+1
|
||||||
attr_writer :taguri
|
attr_writer :taguri
|
||||||
|
@ -78,6 +78,9 @@ class Module
|
||||||
ensure
|
ensure
|
||||||
$VERBOSE = verbose
|
$VERBOSE = verbose
|
||||||
end
|
end
|
||||||
|
remove_method :yaml_as rescue nil
|
||||||
|
alias :yaml_as :syck_yaml_as
|
||||||
|
|
||||||
# Transforms the subclass name into a name suitable for display
|
# Transforms the subclass name into a name suitable for display
|
||||||
# in a subclassed tag.
|
# in a subclassed tag.
|
||||||
def yaml_tag_class_name
|
def yaml_tag_class_name
|
||||||
|
|
|
@ -139,5 +139,13 @@ module Psych
|
||||||
assert_equal 'some string', coder.scalar
|
assert_equal 'some string', coder.scalar
|
||||||
assert_equal :scalar, coder.type
|
assert_equal :scalar, coder.type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class YamlAs
|
||||||
|
yaml_as 'helloworld'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_yaml_as
|
||||||
|
assert_match(/helloworld/, Psych.dump(YamlAs.new))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче