From a17cdfdde29faa7e6c5feb1c31d41e4f42328daa Mon Sep 17 00:00:00 2001 From: tenderlove Date: Wed, 19 Jan 2011 23:05:53 +0000 Subject: * ext/psych/lib/psych/coder.rb (represent_object): arbitrary objects may be passed to the Psych::Coder object. * ext/psych/lib/psych/visitors/yaml_tree.rb: support for visiting arbitrary objects set on the coder. * test/psych/test_coder.rb: supporting test case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/psych/lib/psych/coder.rb | 24 ++++++++++++++++-------- ext/psych/lib/psych/visitors/yaml_tree.rb | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'ext/psych/lib') diff --git a/ext/psych/lib/psych/coder.rb b/ext/psych/lib/psych/coder.rb index c06c9c1e61..2b830d2b21 100644 --- a/ext/psych/lib/psych/coder.rb +++ b/ext/psych/lib/psych/coder.rb @@ -6,17 +6,18 @@ module Psych # objects like Sequence and Scalar may be emitted if +seq=+ or +scalar=+ are # called, respectively. class Coder - attr_accessor :tag, :style, :implicit + attr_accessor :tag, :style, :implicit, :object attr_reader :type, :seq def initialize tag - @map = {} - @seq = [] - @implicit = false - @type = :map - @tag = tag - @style = Psych::Nodes::Mapping::BLOCK - @scalar = nil + @map = {} + @seq = [] + @implicit = false + @type = :map + @tag = tag + @style = Psych::Nodes::Mapping::BLOCK + @scalar = nil + @object = nil end def scalar *args @@ -54,6 +55,13 @@ module Psych self.map = map end + # Emit an arbitrary object +obj+ and +tag+ + def represent_object tag, obj + @tag = tag + @type = :object + @object = obj + end + # Emit a scalar with +value+ def scalar= value @type = :scalar diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index b862528502..e7d182f707 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -342,6 +342,8 @@ module Psych accept v end @emitter.end_mapping + when :object + accept c.object end end -- cgit v1.2.3