diff options
-rw-r--r-- | lib/psych.rb | 9 | ||||
-rw-r--r-- | test/test_psych.rb | 8 |
2 files changed, 17 insertions, 0 deletions
diff --git a/lib/psych.rb b/lib/psych.rb index 2d0cf0c..f1ee542 100644 --- a/lib/psych.rb +++ b/lib/psych.rb @@ -45,4 +45,13 @@ module Psych def self.dump o o.to_yaml end + + ### + # Load multiple documents given in +yaml+, yielding each document to + # the block provided. + def self.load_documents yaml, &block + yaml_ast(yaml).children.each do |child| + block.call child.to_ruby + end + end end diff --git a/test/test_psych.rb b/test/test_psych.rb index 96d0f69..690bf23 100644 --- a/test/test_psych.rb +++ b/test/test_psych.rb @@ -10,4 +10,12 @@ class TestPsych < MiniTest::Unit::TestCase assert Psych.libyaml_version assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION end + + def test_load_documents + docs = [] + Psych.load_documents("--- foo\n...\n--- bar\n...") { |doc| + docs << doc + } + assert_equal %w{ foo bar }, docs + end end |