Module: YAML
- Defined in:
- lib/webget_ramp/yaml.rb
Class Method Summary collapse
-
.load_dir(*dirpaths) ⇒ Object
Specify one or more directory patterns and pass each YAML file in the matching directories to a block.
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.
See [Dir#glob](www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
Example
YAML.load_dir('/tmp/*.yaml'){|yaml_document|
#...whatever you want to do with each yaml document
}
Example to load documents in files ending in “.yaml” and “.yml”
YAML.load_dir('/tmp/*.yaml','/tmp/*.yml','){|yaml_document|
#...whatever you want to do with the yaml document
}
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/webget_ramp/yaml.rb', line 19 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 |