Class: Sambot::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sambot/config.rb

Constant Summary collapse

CONFIGURATION_FILENAME =
'.config.yml'.freeze

Instance Method Summary collapse

Instance Method Details

#read(path = nil) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sambot/config.rb', line 10

def read(path = nil)
  path ||= File.join(Dir.getwd, CONFIGURATION_FILENAME)
  raise ApplicationError, "The configuration file was not found at #{path}." unless File.exist?(path)
  config = YAML.load_file(path)
  raise ApplicationError, 'Missing cookbook name in the .config.yml configuration file' unless config['name']
  raise ApplicationError, 'Missing platforms in the .config.yml configuration file' unless config['platform'] || config['platforms']
  raise ApplicationError, 'Missing version in the .config.yml configuration file' unless config['version']
  raise ApplicationError, 'Missing list of suites in the .config.yml configuration file' unless config['suites']
  raise ApplicationError, 'Missing description in the .config.yml configuration file' unless config['description']
  # Dealing with legacy tech debt of allowing multiple platforms rather than a single platform
  unless config['platforms']
    unless config['platform'].kind_of?(Array)
      config['platform'] = [config['platform']]
    end
    config['platforms'] = config['platform']
  end
  config
end