Module: YAML

Defined in:
lib/sixarm_ruby_yaml_load_glob.rb

Class Method Summary collapse

Class Method Details

.load_glob_documents(*globs) ⇒ Object

Specify file glob patterns, load each file, and yield each YAML document to a block.

Examples:

To load file names that end with “.yml” or “.yaml”


YAML.load_glob_documents("*.yml","*.yaml"){|document|
  ...
}

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sixarm_ruby_yaml_load_glob.rb', line 20

def YAML.load_glob_documents(*globs)
  globs=[*globs.flatten]
  globs.each do |glob|
    Dir[glob].each do |filename|
      File.open(filename) do |file|
        YAML.load_stream(file) do |document|
          yield document
        end #load
      end #file
    end #dir
  end #each
end

.load_glob_keys(*globs) ⇒ Object

Specify file glob patterns, load each file, and yield each YAML key and its values to a block.

Examples:

To load file names that end with “*.yml” or “*.yaml”


YAML.load_glob_keys("*.yml","*.yaml"){|key, values|
  ...
}

See Also:



43
44
45
46
47
48
49
# File 'lib/sixarm_ruby_yaml_load_glob.rb', line 43

def YAML.load_glob_keys(*globs)
  YAML.load_glob_documents(globs){|document|
    document.keys.map{|key|
      yield key, document[key]
    }
  }
end