diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/psych/handler.rb | 15 | ||||
-rw-r--r-- | lib/psych/visitors/emitter.rb | 15 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/psych/handler.rb b/lib/psych/handler.rb index a2aa6bb..d3b9963 100644 --- a/lib/psych/handler.rb +++ b/lib/psych/handler.rb @@ -11,6 +11,21 @@ module Psych # See Psych::Parser for more details class Handler ### + # Configuration options for dumping YAML. + class DumperOptions + attr_accessor :line_width, :indentation, :canonical + + def initialize + @line_width = 0 + @indentation = 2 + @canonical = false + end + end + + # Default dumping options + OPTIONS = DumperOptions.new + + ### # Called with +encoding+ when the YAML stream starts. This method is # called once per stream. A stream may contain multiple documents. # diff --git a/lib/psych/visitors/emitter.rb b/lib/psych/visitors/emitter.rb index 30db176..c886e50 100644 --- a/lib/psych/visitors/emitter.rb +++ b/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 |