Class: Kitchen::Loader::YAML

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/loader/yaml.rb

Overview

YAML file loader for Test Kitchen configuration. This class is responisble for parsing the main YAML file and the local YAML if it exists. Local file configuration will win over the default configuration. The client of this class should not require any YAML loading or parsing logic.

Author:

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ YAML

Creates a new loader that can parse and load YAML files.

Parameters:

  • options (Hash) (defaults to: {})

    configuration for a new loader

Options Hash (options):

  • :project_config (String)

    path to the Kitchen config YAML file (default: ./.kitchen.yml)

  • :local_config (String)

    path to the Kitchen local config YAML file (default: ./.kitchen.local.yml)

  • :global_config (String)

    path to the Kitchen global config YAML file (default: $HOME/.kitchen/config.yml)

  • :process_erb (String)

    whether or not to process YAML through an ERB processor (default: true)

  • :process_local (String)

    whether or not to process a local kitchen YAML file, if it exists (default: true)



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/kitchen/loader/yaml.rb', line 55

def initialize(options = {})
  @config_file =
    File.expand_path(options[:project_config] || default_config_file)
  @local_config_file =
    File.expand_path(options[:local_config] || default_local_config_file)
  @global_config_file =
    File.expand_path(options[:global_config] || default_global_config_file)

  @process_erb = options.fetch(:process_erb, true)
  @process_local = options.fetch(:process_local, true)
  @process_global = options.fetch(:process_global, true)
end

Instance Method Details

#diagnoseHash

Returns a Hash of configuration and other useful diagnostic information.

Returns:

  • (Hash)

    a diagnostic hash



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kitchen/loader/yaml.rb', line 83

def diagnose
  result = Hash.new
  result[:process_erb] = @process_erb
  result[:process_local] = @process_local
  result[:process_global] = @process_global
  result[:global_config] = diagnose_component(:global_yaml, global_config_file)
  result[:project_config] = diagnose_component(:yaml, config_file)
  result[:local_config] = diagnose_component(:local_yaml, local_config_file)
  result[:combined_config] = diagnose_component(:combined_hash)
  result
end

#readHash

Reads, parses, and merges YAML configuration files and returns a Hash of tne merged data.

Returns:

  • (Hash)

    merged configuration data



72
73
74
75
76
77
78
# File 'lib/kitchen/loader/yaml.rb', line 72

def read
  if !File.exist?(config_file)
    raise UserError, "Kitchen YAML file #{config_file} does not exist."
  end

  Util.symbolized_hash(combined_hash)
end