Issue #5978 has been updated by Thomas Sawyer.
Yea, that would suffice. It would still be nice to have a more intuitive/convenient class method though.
What about a new method, `process_stream` or `each_document`, or something like that, to wrap that code? Oh wait... why not just keep `load_documents` method for this and that way it will remain backward compatible with Syck API?
----------------------------------------
Bug #5978: YAML.load_stream should process documents as they are read
https://bugs.ruby-lang.org/issues/5978
Author: Thomas Sawyer
Status: Open
Priority: Normal
Assignee:
Category:
Target version: 2.0.0
ruby -v: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
Psych say YAML.load_documents is deprecated and say to use `YAML.load_stream` instead.
Looking at the implementation for `load_stream()`, looks to me as if it waits for all documents in the stream to load before anything can be done with it.
# File 'lib/psych.rb', line 221
def self.load_stream yaml
parse_stream(yaml).children.map { |child| child.to_ruby }
end
I don't think this should be the case. Ideally `load_stream()` would take a block, and if an IO object is given, read a document, yield it and then read the next document, and so on.
I imagine an Enumerator might be applicable to this as well.
--
http://bugs.ruby-lang.org/