Module: YAMLSafeLoadStream

Defined in:
lib/yaml/safe_load_stream.rb,
lib/yaml/safe_load_stream/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

. in file #{filename}Object

.childrenObject

.in document #{doc_num}Object

.on line #{obj.start_line} column #{obj.start_column} of document #{doc_num}Object

.start_lineObject

.tagObject

.tag #{tag} encountered Object

.tag:yaml.org,Object

Instance Method Details

#safe_load_stream {|document| ... } ⇒ Array

A safe version of YAML.load_stream. Parses a multi document stream and raises if it tries to instantiate any non-standard classes

Yields:

  • (document)

    each document in the stream is yielded if a block is given


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/yaml/safe_load_stream.rb', line 14

module_function def safe_load_stream(yaml, filename = nil)
  streams = []
  ::YAML.parse_stream(yaml, filename) do |stream|
    raise_if_tags(stream, filename)
    if block_given?
      yield stream.to_ruby
    else
      streams << stream.to_ruby
    end
  end
  streams unless block_given?
end