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`)



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/kitchen/loader/yaml.rb', line 46

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



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/kitchen/loader/yaml.rb', line 74

def diagnose
  result = {}
  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



63
64
65
66
67
68
69
# File 'lib/kitchen/loader/yaml.rb', line 63

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

  Util.symbolized_hash(combined_hash)
end