Module: YAML

Defined in:
lib/webget_ruby_ramp/yaml.rb

Overview

YAML extensions

Class Method Summary collapse

Class Method Details

.load_dir(*dirpaths) ⇒ Object

Specify one or more directory patterns and pass each YAML file in the matching directories to a block.

Examples:

To load documents in files ending in “.yaml”

YAML.load_dir('/tmp/*.yaml'){|yaml_document|
  #...whatever you want to do with each yaml document
}

To load documents in files beginning in “foo” or “bar”

YAML.load_dir('/tmp/foo*.yaml','/tmp/bar*.yaml','){|yaml_document|
  #...whatever you want to do with the yaml document
}

See Also:



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/webget_ruby_ramp/yaml.rb', line 24

def YAML.load_dir(*dirpaths)
  dirpaths=[*dirpaths.flatten]
  dirpaths.each do |dirpath|
    Dir[dirpath].each do |filename|
      File.open(filename) do |file|
        YAML.load_documents(file) do |doc|
          yield doc
        end #load
      end #file
    end #dir
  end #each
end