summaryrefslogtreecommitdiff
path: root/ext/psych/lib/psych/visitors/emitter.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-19 00:36:42 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-07-19 00:36:42 +0000
commit1ec93d92c7130f5b56fc87b2d811b42e1a26b6a2 (patch)
treeb723c625d53bae3eb8195b040464b9ea1319ea55 /ext/psych/lib/psych/visitors/emitter.rb
parentac80ad663ee907115bae310ae7f4d0bee6611f0a (diff)
* ext/psych/emitter.c (initialize): allow a configuration object to be
passed to the constructor so that mutation isn't required after instantiation. * ext/psych/lib/psych/handler.rb: add configuration object * ext/psych/lib/psych/visitors/emitter.rb: use configuration object if extra configuration is present. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36458 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/psych/lib/psych/visitors/emitter.rb')
-rw-r--r--ext/psych/lib/psych/visitors/emitter.rb15
1 files changed, 11 insertions, 4 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