2003-05-09 17:25:50 -04:00
|
|
|
module YAML
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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 )
|
|
|
|
@documents[ doc_num ] = doc
|
|
|
|
end
|
|
|
|
|
2005-09-12 23:58:33 -04:00
|
|
|
def emit( io = nil )
|
|
|
|
# opts = @options.dup
|
|
|
|
# opts[:UseHeader] = true if @documents.length > 1
|
|
|
|
out = YAML.emitter
|
|
|
|
out.reset( io || io2 = StringIO.new )
|
2003-05-09 17:25:50 -04:00
|
|
|
@documents.each { |v|
|
2005-09-12 23:58:33 -04:00
|
|
|
v.to_yaml( out )
|
2003-05-09 17:25:50 -04:00
|
|
|
}
|
2005-09-12 23:58:33 -04:00
|
|
|
io || ( io2.rewind; io2.read )
|
2003-05-09 17:25:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|