Module: OdaniaOps::Helper::Config

Defined in:
lib/odania_ops/helper/config.rb

Class Method Summary collapse

Class Method Details

.load_config(folder) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/odania_ops/helper/config.rb', line 5

def load_config(folder)
	config_file = nil
	begin
		config_file = retrieve_config_folder '/etc'
	rescue RuntimeError
		config_file = retrieve_config_folder folder
	end

	$config = {}
	return unless File.exists? config_file

	$logger.debug "Loading config file #{config_file}"
	$config = YAML.load_file(config_file)
	$logger.debug $config.inspect
end

.retrieve_config_folder(start_folder) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/odania_ops/helper/config.rb', line 21

def retrieve_config_folder(start_folder)
	folder = start_folder
	loop do
		break unless File.directory?(folder)

		config_file = File.expand_path('ops-config.yml', folder)
		return config_file if File.exists? config_file

		next_folder = File.expand_path('..', folder)

		break if next_folder.eql?(folder)
		folder = next_folder
	end

	$logger.error "No configuration found! Looking in #{start_folder} and above."
	''
end