Class: Hiera::Config

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

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



47
48
49
# File 'lib/hiera/config.rb', line 47

def [](key)
    @config[key]
end

.include?(key) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/hiera/config.rb', line 43

def include?(key)
    @config.include?(key)
end

.load(source) ⇒ Object

Takes a string or hash as input, strings are treated as filenames hashes are stored as data that would have been in the config file

Unless specified it will only use YAML as backend with a single ‘common’ hierarchy and console logger



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hiera/config.rb', line 8

def load(source)
    @config = {:backends => "yaml",
               :hierarchy => "common"}

    if source.is_a?(String)
        raise "Config file #{source} not found" unless File.exist?(source)

        config = YAML.load_file(source)
        @config.merge! config if config
    elsif source.is_a?(Hash)
        @config.merge! source
    end

    @config[:backends] = [ @config[:backends] ].flatten

    if @config.include?(:logger)
        Hiera.logger = @config[:logger].to_s
    else
        @config[:logger] = "console"
        Hiera.logger = "console"
    end

    @config
end

.load_backendsObject



33
34
35
36
37
38
39
40
41
# File 'lib/hiera/config.rb', line 33

def load_backends
    @config[:backends].each do |backend|
        begin
            require "hiera/backend/#{backend.downcase}_backend"
        rescue LoadError => e
            Hiera.warn "Cannot load backend #{backend}: #{e}"
        end
    end
end