Sha256: 6248f085dd216fdc73d57c53adaa7f34806923b194181c8f9666ca1a85748be4

Contents?: true

Size: 997 Bytes

Versions: 3

Compression:

Stored size: 997 Bytes

Contents

require 'mustache'

module Vcloud
  module Core
    class ConfigLoader

      def load_config(config_file, schema = nil, vars_file = nil)
        if vars_file
          rendered_config = Mustache.render(
            File.read(config_file),
            YAML::load_file(vars_file)
          )
          input_config = YAML::load(rendered_config)
        else
          input_config = YAML::load_file(config_file)
        end

        # There is no way in YAML or Ruby to symbolize keys in a hash
        json_string = JSON.generate(input_config)
        config = JSON.parse(json_string, :symbolize_names => true)

        if schema
          validation = Core::ConfigValidator.validate(:base, config, schema)
          unless validation.valid?
            validation.errors.each do |error|
              Vcloud::Core.logger.fatal(error)
            end
            raise("Supplied configuration does not match supplied schema")
          end
        end

        config
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vcloud-core-0.3.0 lib/vcloud/core/config_loader.rb
vcloud-core-0.2.0 lib/vcloud/core/config_loader.rb
vcloud-core-0.1.0 lib/vcloud/core/config_loader.rb