summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors
diff options
context:
space:
mode:
Diffstat (limited to 'ext/psych/lib/psych/visitors')
-rw-r--r--ext/psych/lib/psych/visitors/emitter.rb15
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb11
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb4
3 files changed, 23 insertions, 7 deletions
diff --git a/ext/psych/lib/psych/visitors/emitter.rb b/ext/psych/lib/psych/visitors/emitter.rb
index 30db17612d..c886e5092e 100644
--- a/ext/psych/lib/psych/visitors/emitter.rb
+++ b/ext/psych/lib/psych/visitors/emitter.rb
@@ -2,10 +2,17 @@ module Psych
module Visitors
class Emitter < Psych::Visitors::Visitor
def initialize io, options = {}
- @handler = Psych::Emitter.new io
- @handler.indentation = options[:indentation] if options[:indentation]
- @handler.canonical = options[:canonical] if options[:canonical]
- @handler.line_width = options[:line_width] if options[:line_width]
+ opts = [:indentation, :canonical, :line_width].find_all { |opt|
+ options.key?(opt)
+ }
+
+ if opts.empty?
+ @handler = Psych::Emitter.new io
+ else
+ du = Handler::DumperOptions.new
+ opts.each { |option| du.send :"#{option}=", options[option] }
+ @handler = Psych::Emitter.new io, du
+ end
end
def visit_Psych_Nodes_Stream o
diff --git a/ext/psych/lib/psych/visitors/to_ruby.rb b/ext/psych/lib/psych/visitors/to_ruby.rb
index 2e082f90b4..088301ac14 100644
--- a/ext/psych/lib/psych/visitors/to_ruby.rb
+++ b/ext/psych/lib/psych/visitors/to_ruby.rb
@@ -147,8 +147,8 @@ module Psych
string = members.delete 'str'
if klass
- string = klass.allocate
- string.replace string
+ string = klass.allocate.replace string
+ register(o, string)
end
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
@@ -222,6 +222,13 @@ module Psych
when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
revive_hash resolve_class($1).new, o
+ when '!omap', 'tag:yaml.org,2002:omap'
+ map = register(o, Psych::Omap.new)
+ o.children.each_slice(2) do |l,r|
+ map[accept(l)] = accept r
+ end
+ map
+
else
revive_hash({}, o)
end
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 80af0466eb..948a976dd1 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -20,6 +20,7 @@ module Psych
@st = {}
@ss = ss
@options = options
+ @coders = []
@dispatch_cache = Hash.new do |h,klass|
method = "visit_#{(klass.name || '').split('::').join('_')}"
@@ -253,7 +254,7 @@ module Psych
maptag = '!ruby/string'
maptag << ":#{o.class}" unless o.class == ::String
- @emitter.start_mapping nil, maptag, false, Nodes::Mapping::BLOCK
+ register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
@emitter.scalar str, nil, tag, plain, quote, style
@@ -406,6 +407,7 @@ module Psych
end
def dump_coder o
+ @coders << o
tag = Psych.dump_tags[o.class]
unless tag
klass = o.class == Object ? nil : o.class.name