* ext/psych/lib/psych/coder.rb (scalar): supporting deprecated methods
* ext/psych/lib/psych/deprecated.rb: supporting deprecated to_yaml_properties method git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
039219b2c9
commit
2db7b7f3fe
@ -1,3 +1,9 @@
|
|||||||
|
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/deprecated.rb: supporting deprecated
|
||||||
|
to_yaml_properties method
|
||||||
|
|
||||||
Sat Apr 17 01:32:50 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
Sat Apr 17 01:32:50 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||||
|
|
||||||
* io.c (rb_io_rewind, rb_io_eof): add rdoc. based on a patch from
|
* io.c (rb_io_rewind, rb_io_eof): add rdoc. based on a patch from
|
||||||
|
@ -7,7 +7,7 @@ module Psych
|
|||||||
# called, respectively.
|
# called, respectively.
|
||||||
class Coder
|
class Coder
|
||||||
attr_accessor :tag, :style, :implicit
|
attr_accessor :tag, :style, :implicit
|
||||||
attr_reader :type, :scalar, :seq
|
attr_reader :type, :seq
|
||||||
|
|
||||||
def initialize tag
|
def initialize tag
|
||||||
@map = {}
|
@map = {}
|
||||||
@ -19,6 +19,15 @@ module Psych
|
|||||||
@scalar = nil
|
@scalar = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def scalar *args
|
||||||
|
if args.length > 0
|
||||||
|
warn "#{caller[0]}: Coder#scalar(a,b,c) is deprecated" if $VERBOSE
|
||||||
|
@tag, @scalar, _ = args
|
||||||
|
@type = :scalar
|
||||||
|
end
|
||||||
|
@scalar
|
||||||
|
end
|
||||||
|
|
||||||
# Emit a map. The coder will be yielded to the block.
|
# Emit a map. The coder will be yielded to the block.
|
||||||
def map tag = @tag, style = @style
|
def map tag = @tag, style = @style
|
||||||
@tag = tag
|
@tag = tag
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require 'date'
|
require 'date'
|
||||||
|
|
||||||
module Psych
|
module Psych
|
||||||
|
DEPRECATED = __FILE__ # :nodoc:
|
||||||
|
|
||||||
module DeprecatedMethods # :nodoc:
|
module DeprecatedMethods # :nodoc:
|
||||||
attr_accessor :taguri
|
attr_accessor :taguri
|
||||||
attr_accessor :to_yaml_style
|
attr_accessor :to_yaml_style
|
||||||
@ -19,3 +21,9 @@ module Psych
|
|||||||
target.psych_to_yaml unless opts[:nodump]
|
target.psych_to_yaml unless opts[:nodump]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Object
|
||||||
|
def to_yaml_properties # :nodoc:
|
||||||
|
instance_variables
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -182,9 +182,7 @@ module Psych
|
|||||||
plain = !quote
|
plain = !quote
|
||||||
end
|
end
|
||||||
|
|
||||||
ivars = o.respond_to?(:to_yaml_properties) ?
|
ivars = find_ivars o
|
||||||
o.to_yaml_properties :
|
|
||||||
o.instance_variables
|
|
||||||
|
|
||||||
scalar = create_scalar str, nil, tag, plain, quote
|
scalar = create_scalar str, nil, tag, plain, quote
|
||||||
|
|
||||||
@ -251,6 +249,19 @@ module Psych
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
# FIXME: remove this method once "to_yaml_properties" is removed
|
||||||
|
def find_ivars target
|
||||||
|
m = target.method(:to_yaml_properties)
|
||||||
|
unless m.source_location.first.start_with?(Psych::DEPRECATED)
|
||||||
|
if $VERBOSE
|
||||||
|
warn "to_yaml_properties is deprecated, please implement \"encode_with(coder)\""
|
||||||
|
end
|
||||||
|
return target.to_yaml_properties
|
||||||
|
end
|
||||||
|
|
||||||
|
target.instance_variables
|
||||||
|
end
|
||||||
|
|
||||||
def append o
|
def append o
|
||||||
@stack.last.children << o
|
@stack.last.children << o
|
||||||
o
|
o
|
||||||
@ -295,9 +306,7 @@ module Psych
|
|||||||
end
|
end
|
||||||
|
|
||||||
def dump_ivars target, map
|
def dump_ivars target, map
|
||||||
ivars = target.respond_to?(:to_yaml_properties) ?
|
ivars = find_ivars target
|
||||||
target.to_yaml_properties :
|
|
||||||
target.instance_variables
|
|
||||||
|
|
||||||
ivars.each do |iv|
|
ivars.each do |iv|
|
||||||
map.children << create_scalar("#{iv.to_s.sub(/^@/, '')}")
|
map.children << create_scalar("#{iv.to_s.sub(/^@/, '')}")
|
||||||
|
@ -131,5 +131,13 @@ module Psych
|
|||||||
assert_equal 'TGIF!', yi.value
|
assert_equal 'TGIF!', yi.value
|
||||||
assert_instance_of YamlInitAndInitWith, yi
|
assert_instance_of YamlInitAndInitWith, yi
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_coder_scalar
|
||||||
|
coder = Psych::Coder.new 'foo'
|
||||||
|
coder.scalar('tag', 'some string', :plain)
|
||||||
|
assert_equal 'tag', coder.tag
|
||||||
|
assert_equal 'some string', coder.scalar
|
||||||
|
assert_equal :scalar, coder.type
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user