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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = nil, options = {}) ⇒ YAML

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

Parameters:

  • config_file (String) (defaults to: nil)

    path to Kitchen config YAML file

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

    configuration for a new loader

Options Hash (options):

  • :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
# File 'lib/kitchen/loader/yaml.rb', line 46

def initialize(config_file = nil, options = {})
  @config_file = File.expand_path(config_file || default_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 Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



36
37
38
# File 'lib/kitchen/loader/yaml.rb', line 36

def config_file
  @config_file
end

Instance Method Details

#diagnoseHash

Returns a Hash of configuration and other useful diagnostic information.

Returns:

  • (Hash)

    a diagnostic hash



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/kitchen/loader/yaml.rb', line 68

def diagnose
  result = Hash.new
  result[:proces_erb] = @process_erb
  result[:process_local] = @process_local
  result[:process_global] = @process_global
  if File.exists?(global_config_file)
    result[:global_config] =
      { :filename => global_config_file, :raw_data => global_yaml }
  end
  result[:project_config] =
    { :filename => config_file, :raw_data => yaml }
  if File.exists?(local_config_file)
    result[:local_config] =
      { :filename => local_config_file, :raw_data => local_yaml }
  end
  result[:combined_config] = { :raw_data => 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



57
58
59
60
61
62
63
# File 'lib/kitchen/loader/yaml.rb', line 57

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

  Util.symbolized_hash(combined_hash)
end