Sha256: fbfdbcc84574dedfc20cc0f56faa6a6a729e3d5f6bc3a7f3890335d83ddff0f7

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

require 'yaml'

class ConfigBuilder::Loader::YAML

  # Load configuration from YAML files in one or more directories
  #
  # @overload yamldir(path)
  #   @param path [String] A directory path containing YAML files
  # @overload yamldir(paths)
  #   @param paths [Array<String>] A list of directory paths containing YAML files
  #
  # @return [Hash]
  def yamldir(input)
    dirs = Array(input)

    files = dirs.map do |dir|
      pattern = File.join(dir, '*.{yml,yaml}')
      Dir.glob(pattern)
    end.flatten

    rv = {}

    files.each do |file|
      contents = ::YAML.load_file(file)
      if contents.is_a? Hash
        rv.merge! contents
      end
    end

    rv
  end

  # Load configuration from a file
  #
  # @param file_path [String]
  #
  # @return [Hash]
  def yamlfile(file_path)
    ::YAML.load_file(file_path)
  end

  ConfigBuilder::Loader.register(:yaml, self)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-config_builder-0.6.0 lib/config_builder/loader/yaml.rb