Sha256: 4a01902fed1f90dad8678fd4a2e9100ef6dce7c7306f8304991607f3db1bef51

Contents?: true

Size: 679 Bytes

Versions: 4

Compression:

Stored size: 679 Bytes

Contents

require 'yaml'

class ConfigBuilder::Loader::YAML

  # Load configuration from all files in a given directory
  #
  # @param dir_path [String]
  #
  # @return [Hash]
  def yamldir(dir_path)
    glob_path = File.join(dir_path, '*.{yml,yaml}')

    rv = {}
    Dir.glob(glob_path).each do |file|
      contents = ::YAML.load_file(file)

      if contents.is_a? Hash
        rv.merge! contents
      else
        # TODO warn on non-hash YAML
      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

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-config_builder-0.5.0 lib/config_builder/loader/yaml.rb
vagrant-config_builder-0.4.0 lib/config_builder/loader/yaml.rb
vagrant-config_builder-0.3.1 lib/config_builder/loader/yaml.rb
vagrant-config_builder-0.3.0 lib/config_builder/loader/yaml.rb