Class: YamlWriteStream
- Inherits:
-
Object
show all
- Defined in:
- lib/yaml-write-stream.rb,
lib/yaml-write-stream/version.rb,
lib/yaml-write-stream/stateful.rb,
lib/yaml-write-stream/yielding.rb
Defined Under Namespace
Classes: EndOfStreamError, NotInMapError, NotInSequenceError, StatefulMappingWriter, StatefulSequenceWriter, StatefulWriter, YieldingMappingWriter, YieldingSequenceWriter, YieldingWriter
Constant Summary
collapse
- VERSION =
'2.0.1'
Class Method Summary
collapse
Class Method Details
.from_stream(stream, encoding = Psych::Parser::UTF8) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/yaml-write-stream.rb', line 14
def from_stream(stream, encoding = Psych::Parser::UTF8)
emitter = Psych::Emitter.new(stream)
emitter.start_stream(convert_encoding(encoding))
emitter.start_document([], [], true)
if block_given?
yield writer = YieldingWriter.new(emitter, stream)
writer.close
nil
else
StatefulWriter.new(emitter, stream)
end
end
|
.open(path, encoding = Psych::Parser::UTF8, &block) ⇒ Object
9
10
11
12
|
# File 'lib/yaml-write-stream.rb', line 9
def open(path, encoding = Psych::Parser::UTF8, &block)
handle = ::File.open(path, 'w')
from_stream(handle, encoding, &block)
end
|