lib/psych/visitors/yaml_tree.rb in psych-2.0.0 vs lib/psych/visitors/yaml_tree.rb in psych-2.0.1

- old
+ new

@@ -3,11 +3,11 @@ require 'psych/class_loader' module Psych module Visitors ### - # YAMLTree builds a YAML ast given a ruby object. For example: + # YAMLTree builds a YAML ast given a Ruby object. For example: # # builder = Psych::Visitors::YAMLTree.new # builder << { :foo => 'bar' } # builder.tree # => #<Psych::Nodes::Stream .. } # @@ -45,10 +45,19 @@ class_loader = ClassLoader.new ss = ScalarScanner.new class_loader new(emitter, ss, options) end + def self.new emitter = nil, ss = nil, options = nil + return super if emitter && ss && options + + if $VERBOSE + warn "This API is deprecated, please pass an emitter, scalar scanner, and options or call #{self}.create() (#{caller.first})" + end + create emitter, ss + end + def initialize emitter, ss, options super() @started = false @finished = false @emitter = emitter @@ -205,11 +214,11 @@ register o, @emitter.scalar(formatted, nil, tag, false, false, Nodes::Scalar::ANY) end def visit_Time o formatted = format_time o - @emitter.scalar formatted, nil, nil, true, false, Nodes::Scalar::ANY + register o, @emitter.scalar(formatted, nil, nil, true, false, Nodes::Scalar::ANY) end def visit_Rational o register o, @emitter.start_mapping(nil, '!ruby/object:Rational', false, Nodes::Mapping::BLOCK) @@ -277,9 +286,11 @@ style = Nodes::Scalar::LITERAL plain = false quote = false elsif o =~ /\n/ style = Nodes::Scalar::LITERAL + elsif o =~ /^\W/ + style = Nodes::Scalar::DOUBLE_QUOTED else unless String === @ss.tokenize(o) style = Nodes::Scalar::SINGLE_QUOTED end end