module YAMLSafeLoadStream
Public Instance Methods
safe_load_stream(yaml, filename = nil) { |to_ruby| ... }
click to toggle source
A safe version of YAML.load_stream. Parses a multi document stream and raises if it tries to instantiate any non-standard classes
@param yaml [String] yaml content @param filename [String] filename to be used in exception messages @yield [document] each document in the stream is yielded if a block is given @return [Array] when a block is not given, returns an Array of documents
# File lib/yaml/safe_load_stream.rb, line 14 def safe_load_stream(yaml, filename = nil) result = [] ::YAML.parse_stream(yaml, filename) do |stream| raise_if_tags(stream, filename) result << if block_given? yield(stream.to_ruby) else stream.to_ruby end end result end