summaryrefslogtreecommitdiff
path: root/ext/syck/lib/syck/stream.rb
blob: cd77a033c68bb8894a6a162d4c53635f75204dc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Syck

	#
	# YAML::Stream -- for emitting many documents
	#
	class Stream

		attr_accessor :documents, :options

		def initialize( opts = {} )
			@options = opts
			@documents = []
		end

        def []( i )
            @documents[ i ]
        end

		def add( doc )
			@documents << doc
		end

		def edit( doc_num, doc )
                  warn "#{caller[0]}: edit is deprecated" if $VERBOSE
			@documents[ doc_num ] = doc
		end

		def emit( io = nil )
            # opts = @options.dup
			# opts[:UseHeader] = true if @documents.length > 1
            out = Syck.emitter
            out.reset( io || io2 = StringIO.new )
            @documents.each { |v|
                v.to_yaml( out )
            }
            io || ( io2.rewind; io2.read )
		end

	end

end